From ddb7fa04ca177e04cd266fa78e2af160aa9d25f3 Mon Sep 17 00:00:00 2001 From: samwiseg00 Date: Sun, 27 May 2018 17:44:35 -0400 Subject: [PATCH] add timestamps for rich metadata info on discord --- plexpy/helpers.py | 13 ++++++++----- plexpy/notifiers.py | 5 +++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/plexpy/helpers.py b/plexpy/helpers.py index 03a20fb4..fe0928c6 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -209,6 +209,9 @@ def now(): now = datetime.datetime.now() return now.strftime("%Y-%m-%d %H:%M:%S") +def utc_now_iso(): + utcnow = datetime.datetime.utcnow() + return utcnow.isoformat() def human_duration(s, sig='dhms'): @@ -949,7 +952,7 @@ def parse_condition_logic_string(s, num_cond=0): """ valid_tokens = re.compile(r'(\(|\)|and|or)') conditions_pattern = re.compile(r'{\d+}') - + tokens = [x.strip() for x in re.split(valid_tokens, s.lower()) if x.strip()] stack = [[]] @@ -960,7 +963,7 @@ def parse_condition_logic_string(s, num_cond=0): close_bracket_next = False nest_and = 0 nest_nest_and = 0 - + for i, x in enumerate(tokens): if open_bracket_next and x == '(': stack[-1].append([]) @@ -971,7 +974,7 @@ def parse_condition_logic_string(s, num_cond=0): close_bracket_next = False if nest_and: nest_nest_and += 1 - + elif close_bracket_next and x == ')': stack.pop() if not stack: @@ -1000,7 +1003,7 @@ def parse_condition_logic_string(s, num_cond=0): if nest_and > nest_nest_and: stack.pop() nest_and -= 1 - + elif bool_next and x == 'and' and i < len(tokens)-1: stack[-1].append([]) stack.append(stack[-1][-1]) @@ -1011,7 +1014,7 @@ def parse_condition_logic_string(s, num_cond=0): open_bracket_next = True close_bracket_next = False nest_and += 1 - + elif bool_next and x == 'or' and i < len(tokens)-1: stack[-1].append(x) cond_next = True diff --git a/plexpy/notifiers.py b/plexpy/notifiers.py index 069e31e2..145ded30 100644 --- a/plexpy/notifiers.py +++ b/plexpy/notifiers.py @@ -420,7 +420,7 @@ def get_notifiers(notifier_id=None, notify_action=None): db = database.MonitorDatabase() result = db.select('SELECT id, agent_id, agent_name, agent_label, friendly_name, %s FROM notifiers %s' % (', '.join(notify_actions), where), args=args) - + for item in result: item['active'] = int(any([item.pop(k) for k in item.keys() if k in notify_actions])) @@ -1145,7 +1145,8 @@ class DISCORD(Notifier): plex_url = pretty_metadata.get_plex_url() # Build Discord post attachment - attachment = {'title': title + attachment = {'title': title, + 'timestamp': helpers.utc_now_iso() } if self.config['color']: