mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -07:00
Add datestamp and timestamp notification options
This commit is contained in:
parent
cc857364f4
commit
651b57a93f
3 changed files with 94 additions and 2 deletions
|
@ -1104,6 +1104,14 @@ available_notification_agents = sorted(notifiers.available_notification_agents()
|
|||
<td><strong>{action}</strong></td>
|
||||
<td>The action that triggered the notification.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>{datestamp}</strong></td>
|
||||
<td>The date the notification was triggered.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>{timestamp}</strong></td>
|
||||
<td>The time the notification was triggered.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>{user}</strong></td>
|
||||
<td>The username of the person streaming.</td>
|
||||
|
|
|
@ -447,3 +447,84 @@ def sanitize(string):
|
|||
return unicode(string).replace('<','<').replace('>','>')
|
||||
else:
|
||||
return ''
|
||||
|
||||
def parse_js_date(date):
|
||||
"""
|
||||
Taken from moment library.
|
||||
|
||||
Translate the easy-to-use JavaScript format strings to Python's cumbersome
|
||||
strftime format. Also, this is some ugly code -- and it's completely
|
||||
order-dependent.
|
||||
"""
|
||||
# AM/PM
|
||||
if 'A' in date:
|
||||
date = date.replace('A', '%p')
|
||||
elif 'a' in date:
|
||||
date = date.replace('a', '%P')
|
||||
# 24 hours
|
||||
if 'HH' in date:
|
||||
date = date.replace('HH', '%H')
|
||||
elif 'H' in date:
|
||||
date = date.replace('H', '%k')
|
||||
# 12 hours
|
||||
elif 'hh' in date:
|
||||
date = date.replace('hh', '%I')
|
||||
elif 'h' in date:
|
||||
date = date.replace('h', '%l')
|
||||
# Minutes
|
||||
if 'mm' in date:
|
||||
date = date.replace('mm', '%min')
|
||||
elif 'm' in date:
|
||||
date = date.replace('m', '%min')
|
||||
# Seconds
|
||||
if 'ss' in date:
|
||||
date = date.replace('ss', '%S')
|
||||
elif 's' in date:
|
||||
date = date.replace('s', '%S')
|
||||
# Milliseconds
|
||||
if 'SSS' in date:
|
||||
date = date.replace('SSS', '%3')
|
||||
# Years
|
||||
if 'YYYY' in date:
|
||||
date = date.replace('YYYY', '%Y')
|
||||
elif 'YY' in date:
|
||||
date = date.replace('YY', '%y')
|
||||
# Months
|
||||
if 'MMMM' in date:
|
||||
date = date.replace('MMMM', '%B')
|
||||
elif 'MMM' in date:
|
||||
date = date.replace('MMM', '%b')
|
||||
elif 'MM' in date:
|
||||
date = date.replace('MM', '%m')
|
||||
elif 'M' in date:
|
||||
date = date.replace('M', '%m')
|
||||
# Days of the week
|
||||
if 'dddd' in date:
|
||||
date = date.replace('dddd', '%A')
|
||||
elif 'ddd' in date:
|
||||
date = date.replace('ddd', '%a')
|
||||
elif 'dd' in date:
|
||||
date = date.replace('dd', '%w')
|
||||
elif 'd' in date:
|
||||
date = date.replace('d', '%u')
|
||||
# Days of the year
|
||||
if 'DDDD' in date:
|
||||
date = date.replace('DDDD', '%j')
|
||||
elif 'DDD' in date:
|
||||
date = date.replace('DDD', '%j')
|
||||
# Days of the month
|
||||
elif 'DD' in date:
|
||||
date = date.replace('DD', '%d')
|
||||
# 'Do' not valid python time format
|
||||
elif 'Do' in date:
|
||||
date = date.replace('Do', '')
|
||||
elif 'D' in date:
|
||||
date = date.replace('D', '%d')
|
||||
# Timezone
|
||||
if 'zz' in date:
|
||||
date = date.replace('zz', '%Z')
|
||||
# A necessary evil right now...
|
||||
if '%min' in date:
|
||||
date = date.replace('%min', '%M')
|
||||
|
||||
return date
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
import re
|
||||
import time
|
||||
import re
|
||||
|
||||
from plexpy import logger, config, notifiers, database, helpers, plextv, pmsconnect
|
||||
import plexpy
|
||||
|
@ -525,6 +524,8 @@ def build_notify_text(session=None, timeline=None, state=None):
|
|||
'server_uptime': server_uptime,
|
||||
'streams': stream_count,
|
||||
'action': state,
|
||||
'datestamp': time.strftime(helpers.parse_js_date(plexpy.CONFIG.DATE_FORMAT)),
|
||||
'timestamp': time.strftime(helpers.parse_js_date(plexpy.CONFIG.TIME_FORMAT)),
|
||||
'user': user,
|
||||
'platform': platform,
|
||||
'player': player,
|
||||
|
@ -792,7 +793,9 @@ def build_server_notify_text(state=None):
|
|||
|
||||
available_params = {'server_name': server_name,
|
||||
'server_uptime': server_uptime,
|
||||
'action': state}
|
||||
'action': state,
|
||||
'datestamp': time.strftime(helpers.parse_js_date(plexpy.CONFIG.DATE_FORMAT)),
|
||||
'timestamp': time.strftime(helpers.parse_js_date(plexpy.CONFIG.TIME_FORMAT))}
|
||||
|
||||
# Default text
|
||||
subject_text = 'PlexPy (%s)' % server_name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue