Skip to content

Commit

Permalink
Convert notify list to dict
Browse files Browse the repository at this point in the history
  • Loading branch information
ethan-nelson committed Feb 16, 2017
1 parent 86a1b8b commit 4d222f3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
20 changes: 11 additions & 9 deletions osmhm/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ def user_filter(changesets, notification=False, notifier=send_notification.send_
for user in watched_users:
if fnmatch.fnmatch(changeset['username'].encode('utf-8'), user['username']):
inserts.insert_user_event(changeset, user['id'])

notify_list.append([(changeset['timestamp'], changesetid, changeset['username'].encode('utf8'),
changeset['create'], changeset['modify'], changeset['delete'])] + user)
notify_list.append({'timestamp': changeset['timestamp'], 'changesetid': changesetid,
'username': changeset['username'].encode('utf8'), 'create': changeset['create'],
'modify': changeset['modify'], 'delete': changeset['delete'], 'author': user['author'],
'address': user['email'], 'reason': user['reason']})
if notify_list and notification:
send_notification.send_notification(notify_list, 'user', notifier=notifier)

Expand Down Expand Up @@ -136,9 +137,10 @@ def object_filter(objects, notification=False, notifier=send_notification.send_m
elif item['delete'] == 1:
item['action'] = 4
inserts.insert_object_event(item, obj['id'])

notify_list.append([(item['timestamp'], item['changeset'], item['username'].encode('utf8'),
item['action'], item_id)] + obj)
notify_list.append({'timestamp': item['timestamp'], 'changesetid': item['changeset'],
'username': item['username'].encode('utf8'),
'action': item['action'], 'element': item_id,
'author': obj['author'], 'address': obj['email'], 'reason': obj['reason']})
if notify_list and notification:
send_notification.send_notification(notify_list, 'object', notifier=notifier)

Expand All @@ -163,8 +165,8 @@ def key_filter(objects, notification=False, notifier=send_notification.send_mail
elif item['delete'] == 1:
item['action'] = 4
inserts.insert_key_event(item, item_key, key['id'])

notify_list.append([(item['timestamp'], item['changeset'], item['username'].encode('utf8'),
item['action'], item_key, item['tags'][item_key])])
notify_list.append({'timestamp': item['timestamp'], 'changesetid': item['changeset'],
'username': item['username'].encode('utf8'), 'action': item['action'],
'key': item_key, 'value': item['tags'][item_key]})
if notify_list and notification:
send_notification.send_notification(notify_list, 'key', notifier=notifier)
26 changes: 16 additions & 10 deletions osmhm/send_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def send_notification(notify_list, notification_type, notifier=send_mail):
tos = {}

for entry in notify_list:
if entry[6]:
if entry['address'] is not '':
if notification_type == 'user':
MSG = """
Dear %s,
Expand All @@ -41,18 +41,24 @@ def send_notification(notify_list, notification_type, notifier=send_mail):
Best,
OSM Hall Monitor
""" % (entry[4], entry[0][0], entry[0][2], entry[0][1], entry[0][3], entry[0][4], entry[0][5], entry[3])
""" % (entry['author'], entry['timestamp'], entry['username'], entry['changesetid'], entry['create'], entry['modify'], entry['delete'], entry['reason'])

TO = entry[6]
NEWSUBJECT = '%s User %s ' % (SUBJECT, entry[0][2])
TO = entry['address']
NEWSUBJECT = '%s User %s ' % (SUBJECT, entry['username'])

elif notification_type == 'object':
if 'n' == entry[0][4][0]:
if 'n' == entry['element'][0]:
pre = 'node'
elif 'w' == entry[0][4][0]:
elif 'w' == entry['element'][0]:
pre = 'way'
elif 'r' == entry[0][4][0]:
elif 'r' == entry['element'][0]:
pre = 'relation'
if entry['action'] == 1:
act = 'create'
elif entry['action'] == 2:
act = 'modify'
elif entry['action'] == 4:
act = 'delete'
MSG = """
Dear %s,
OSM Hall Monitor has detected an event for your consideration.
Expand All @@ -70,10 +76,10 @@ def send_notification(notify_list, notification_type, notifier=send_mail):
Best,
OSM Hall Monitor
""" % (entry[4], entry[0][0], pre, entry[0][4][1:], entry[0][1], entry[0][3], entry[0][2], entry[3])
""" % (entry['author'], entry['timestamp'], pre, entry['element'][1:], entry['changesetid'], act, entry['username'], entry['reason'])

TO = entry[6]
NEWSUBJECT = '%s Object %s ' % (SUBJECT, entry[0][4])
TO = entry['address']
NEWSUBJECT = '%s Object %s ' % (SUBJECT, entry['element'])
else:
print 'Notification type unknown'
continue
Expand Down

0 comments on commit 4d222f3

Please sign in to comment.