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()) |