Index: filters/get_subscriptions.py |
diff --git a/filters/get_subscriptions.py b/filters/get_subscriptions.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..56b5910b2eab322072708a6c2fa9d562d6d09280 |
--- /dev/null |
+++ b/filters/get_subscriptions.py |
@@ -0,0 +1,37 @@ |
+# 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 |
+import tarfile |
+import urllib |
+ |
+from sitescripts.subscriptions.subscriptionParser import parse_file, calculate_supplemented |
+ |
+def get_subscriptions(_): |
Sebastian Noack
2015/02/27 11:10:49
I feel that we begin to misuse template filters. D
Sebastian Noack
2015/02/27 14:42:45
Since Dave apparently doesn't have an opinion here
Wladimir Palant
2015/02/27 15:37:02
Sure, we are misusing the filters mechanism here,
Sebastian Noack
2015/02/27 15:40:43
Sounds good to me.
|
+ result = {} |
+ source = urllib.urlopen("https://hg.adblockplus.org/subscriptionlist/archive/default.tar.gz") |
Sebastian Noack
2015/02/27 11:10:49
The file-like object returned by urllib.urlopen()
kzar
2015/02/27 14:21:07
Done.
|
+ with tarfile.open(fileobj=source, mode="r|gz") as archive: |
+ for fileinfo in archive: |
+ if not fileinfo.name.endswith(".subscription"): |
Sebastian Noack
2015/02/27 11:10:49
Nit: os.path.splitext(fileinfo.name)[1] == ".subsc
kzar
2015/02/27 14:21:07
Done.
|
+ continue |
+ |
+ filedata = parse_file(fileinfo.name, codecs.getreader('utf8')(archive.extractfile(fileinfo))) |
Sebastian Noack
2015/02/27 11:10:49
Nit: Maybe initializing the utf8 reader above the
kzar
2015/02/27 14:21:07
Done.
|
+ if filedata.unavailable: |
+ continue |
+ |
+ result[filedata.name] = filedata |
+ |
+ calculate_supplemented(result) |
+ return result.values() |