Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/notifications/parser.py

Issue 29327106: Issue 3048 - Mark inactive notifications instead of removing them (Closed)
Patch Set: Created Sept. 10, 2015, 11:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH 4 # Copyright (C) 2006-2015 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive: 111 with tarfile.open(mode="r:", fileobj=StringIO(data)) as archive:
112 for fileinfo in archive: 112 for fileinfo in archive:
113 name = fileinfo.name 113 name = fileinfo.name
114 if name.startswith("./"): 114 if name.startswith("./"):
115 name = name[2:] 115 name = name[2:]
116 116
117 if fileinfo.type == tarfile.REGTYPE: 117 if fileinfo.type == tarfile.REGTYPE:
118 data = codecs.getreader("utf8")(archive.extractfile(fileinfo)) 118 data = codecs.getreader("utf8")(archive.extractfile(fileinfo))
119 try: 119 try:
120 notification = _parse_notification(data, name) 120 notification = _parse_notification(data, name)
121 if "inactive" in notification: 121 if not "inactive" in notification:
122 continue 122 current_time = datetime.datetime.now()
123 current_time = datetime.datetime.now() 123 start = notification.pop("start", None)
124 start = notification.pop("start", None) 124 end = notification.pop("end", None)
125 if start is not None and current_time < start: 125 if ((start is not None and current_time < start) or
126 continue 126 (end is not None and current_time > end)):
Sebastian Noack 2015/09/10 13:29:20 I think I found a way to simplify that logic: s
Felix Dahlke 2015/09/11 07:04:43 Indeed, that's much better - done.
127 end = notification.pop("end", None) 127 notification["inactive"] = True
128 if end is not None and current_time > end:
129 continue
130 notifications.append(notification) 128 notifications.append(notification)
131 except: 129 except:
132 traceback.print_exc() 130 traceback.print_exc()
133 return notifications 131 return notifications
OLDNEW
« no previous file with comments | « no previous file | sitescripts/notifications/test/notification.py » ('j') | sitescripts/notifications/web/notification.py » ('J')

Powered by Google App Engine
This is Rietveld