summaryrefslogtreecommitdiffstats
path: root/scripts/convertpsl.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/convertpsl.py')
-rwxr-xr-xscripts/convertpsl.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/convertpsl.py b/scripts/convertpsl.py
new file mode 100755
index 0000000..3cd78be
--- /dev/null
+++ b/scripts/convertpsl.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+# script based on
+# https://github.com/adblockplus/buildtools/blob/d090e00610a58cebc78478ae33e896e6b949fc12/publicSuffixListUpdater.py
+
+from __future__ import print_function
+
+import json
+import sys
+
+def convert(psl_text):
+ suffixes = {}
+
+ for line in psl_text:
+ line = line.rstrip()
+ if line.startswith('//') or '.' not in line:
+ continue
+ if line.startswith('*.'):
+ suffixes[line[2:]] = 2
+ elif line.startswith('!'):
+ suffixes[line[1:]] = 0
+ else:
+ suffixes[line] = 1
+
+ return suffixes
+
+
+if __name__ == '__main__':
+ with open(sys.argv[1], 'r+') as f:
+ psl = convert(f)
+ f.seek(0)
+ text = 'window.publicSuffixes = %s;' % (
+ json.dumps(psl, sort_keys=True, indent=2, separators=(',', ': '))
+ )
+ print(text, file=f)
+ f.truncate()