| OLD | NEW |
| 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-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 last_version = params.get("lastVersion", ["unknown"])[0] | 208 last_version = params.get("lastVersion", ["unknown"])[0] |
| 209 if info["file"] == "notification.json" and last_version == "0" and ( | 209 if info["file"] == "notification.json" and last_version == "0" and ( |
| 210 (info["addonName"] == "adblockplus" and info["addonVersion"] == "2.3.1") o
r | 210 (info["addonName"] == "adblockplus" and info["addonVersion"] == "2.3.1") o
r |
| 211 (info["addonName"] in ("adblockpluschrome", "adblockplusopera") and info["
addonVersion"] == "1.5.2") | 211 (info["addonName"] in ("adblockpluschrome", "adblockplusopera") and info["
addonVersion"] == "1.5.2") |
| 212 ): | 212 ): |
| 213 # Broken notification version number in these releases, treat like unknown | 213 # Broken notification version number in these releases, treat like unknown |
| 214 last_version = "unknown" | 214 last_version = "unknown" |
| 215 | 215 |
| 216 if last_version == "unknown": | 216 if last_version == "unknown": |
| 217 info["downloadInterval"] = "unknown" | 217 info["downloadInterval"] = "unknown" |
| 218 info["previousDownload"] = "unknown" |
| 218 elif last_version == "0": | 219 elif last_version == "0": |
| 219 info["downloadInterval"] = "unknown" | 220 info["downloadInterval"] = "unknown" |
| 221 info["previousDownload"] = "unknown" |
| 220 info["firstDownload"] = True | 222 info["firstDownload"] = True |
| 221 else: | 223 else: |
| 222 try: | 224 try: |
| 223 last_update = parse_lastversion(last_version) | 225 last_update = parse_lastversion(last_version) |
| 224 diff = info["time"] - last_update | 226 diff = info["time"] - last_update |
| 225 if diff.days >= 365: | 227 if diff.days >= 365: |
| 226 info["downloadInterval"] = "%i year(s)" % (diff.days / 365) | 228 info["downloadInterval"] = "%i year(s)" % (diff.days / 365) |
| 227 elif diff.days >= 30: | 229 elif diff.days >= 30: |
| 228 info["downloadInterval"] = "%i month(s)" % (diff.days / 30) | 230 info["downloadInterval"] = "%i month(s)" % (diff.days / 30) |
| 229 elif diff.days >= 1: | 231 elif diff.days >= 1: |
| 230 info["downloadInterval"] = "%i day(s)" % diff.days | 232 info["downloadInterval"] = "%i day(s)" % diff.days |
| 231 else: | 233 else: |
| 232 info["downloadInterval"] = "%i hour(s)" % (diff.seconds / 3600) | 234 info["downloadInterval"] = "%i hour(s)" % (diff.seconds / 3600) |
| 233 | 235 |
| 236 diffdays = (info["time"].date() - last_update.date()).days |
| 237 if diffdays == 0: |
| 238 info["previousDownload"] = "same day" |
| 239 elif diffdays < 30: |
| 240 info["previousDownload"] = "%i day(s)" % diffdays |
| 241 elif diffdays < 365: |
| 242 info["previousDownload"] = "%i month(s)" % (diffdays / 30) |
| 243 else: |
| 244 info["previousDownload"] = "%i year(s)" % (diffdays / 365) |
| 245 |
| 234 if last_update.year != info["time"].year or last_update.month != info["tim
e"].month: | 246 if last_update.year != info["time"].year or last_update.month != info["tim
e"].month: |
| 235 info["firstInMonth"] = info["firstInDay"] = True | 247 info["firstInMonth"] = info["firstInDay"] = True |
| 236 elif last_update.day != info["time"].day: | 248 elif last_update.day != info["time"].day: |
| 237 info["firstInDay"] = True | 249 info["firstInDay"] = True |
| 238 | 250 |
| 239 if get_week(last_update) != get_week(info["time"]): | 251 if get_week(last_update) != get_week(info["time"]): |
| 240 info["firstInWeek"] = True | 252 info["firstInWeek"] = True |
| 241 except ValueError: | 253 except ValueError: |
| 242 info["downloadInterval"] = "unknown" | 254 info["downloadInterval"] = "unknown" |
| 255 info["previousDownload"] = "unknown" |
| 243 pass | 256 pass |
| 244 | 257 |
| 245 def parse_addon_name(file): | 258 def parse_addon_name(file): |
| 246 if "/" in file: | 259 if "/" in file: |
| 247 return file.split("/")[-2] | 260 return file.split("/")[-2] |
| 248 else: | 261 else: |
| 249 return None | 262 return None |
| 250 | 263 |
| 251 def parse_gecko_query(query): | 264 def parse_gecko_query(query): |
| 252 params = urlparse.parse_qs(query) | 265 params = urlparse.parse_qs(query) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 if __name__ == "__main__": | 405 if __name__ == "__main__": |
| 393 setupStderr() | 406 setupStderr() |
| 394 | 407 |
| 395 verbose = (len(sys.argv) >= 2 and sys.argv[1] == "verbose") | 408 verbose = (len(sys.argv) >= 2 and sys.argv[1] == "verbose") |
| 396 geo = pygeoip.GeoIP(get_config().get("stats", "geoip_db"), pygeoip.MEMORY_CACH
E) | 409 geo = pygeoip.GeoIP(get_config().get("stats", "geoip_db"), pygeoip.MEMORY_CACH
E) |
| 397 geov6 = pygeoip.GeoIP(get_config().get("stats", "geoipv6_db"), pygeoip.MEMORY_
CACHE) | 410 geov6 = pygeoip.GeoIP(get_config().get("stats", "geoipv6_db"), pygeoip.MEMORY_
CACHE) |
| 398 result = parse_stdin(geo, geov6, verbose) | 411 result = parse_stdin(geo, geov6, verbose) |
| 399 | 412 |
| 400 with codecs.open(get_config().get("stats", "tempFile"), "wb", encoding="utf-8"
) as file: | 413 with codecs.open(get_config().get("stats", "tempFile"), "wb", encoding="utf-8"
) as file: |
| 401 json.dump(result, file, indent=2, sort_keys=True) | 414 json.dump(result, file, indent=2, sort_keys=True) |
| OLD | NEW |