diff --git a/osmhm/filters.py b/osmhm/filters.py index 0e9be99..9f06f50 100644 --- a/osmhm/filters.py +++ b/osmhm/filters.py @@ -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) @@ -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) @@ -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) diff --git a/osmhm/send_notification.py b/osmhm/send_notification.py index b50f87c..4551ac6 100644 --- a/osmhm/send_notification.py +++ b/osmhm/send_notification.py @@ -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, @@ -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. @@ -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