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

Unified Diff: filters/get_subscriptions.py

Issue 5636796054503424: Issue 1170 - [adblockplus.org Anwiki to CMS migration] Migrate content (Closed)
Patch Set: Addressed palant's feedback. Created Feb. 26, 2015, 7:48 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | filters/parse_interface.py » ('j') | includes/interface.tmpl » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: filters/get_subscriptions.py
diff --git a/filters/get_subscriptions.py b/filters/get_subscriptions.py
new file mode 100644
index 0000000000000000000000000000000000000000..d8ec68f8103ce38e693325c8e86fdc73a8ae948c
--- /dev/null
+++ b/filters/get_subscriptions.py
@@ -0,0 +1,41 @@
+# This file is part of the Adblock Plus website,
+# Copyright (C) 2006-2015 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import codecs, tarfile, urllib
Wladimir Palant 2015/02/26 20:35:03 Nit: One import per line please, as required by PE
kzar 2015/02/26 21:49:13 Done.
+
+from sitescripts.subscriptions.subscriptionParser import parse_file, calculate_supplemented
+
+def get_subscriptions(_):
+ def subscription_dict(subscription):
+ d = subscription._data
+ if "supplemented" in d:
+ d["supplemented"] = [subscription_dict(s) for s in d["supplemented"]]
+ return d
Wladimir Palant 2015/02/26 20:35:03 Why is this necessary? The original template in th
kzar 2015/02/26 21:49:13 Done.
+
+ result = {}
+ source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/default.tar.gz")
+ with tarfile.open(fileobj=source, mode="r|gz") as archive:
+ for fileinfo in archive:
+ if not fileinfo.name.endswith(".subscription"):
+ continue
+
+ filedata = parse_file(fileinfo.name, codecs.getreader('utf8')(archive.extractfile(fileinfo)))
+ if filedata.unavailable:
+ continue
+
+ result[filedata.name] = filedata
+
+ calculate_supplemented(result)
+ return map(subscription_dict, result.itervalues())
« no previous file with comments | « no previous file | filters/parse_interface.py » ('j') | includes/interface.tmpl » ('J')

Powered by Google App Engine
This is Rietveld