diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 19:47:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 19:47:39 +0000 |
commit | 8d13bdc6cac0e20c43c6f909fc0208774b9c5c84 (patch) | |
tree | 5fd46925c6b4a881c9208772ed8e5cc0588bc164 /scripts/convertpsl.py | |
parent | Initial commit. (diff) | |
download | privacybadger-8d13bdc6cac0e20c43c6f909fc0208774b9c5c84.tar.xz privacybadger-8d13bdc6cac0e20c43c6f909fc0208774b9c5c84.zip |
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'scripts/convertpsl.py')
-rwxr-xr-x | scripts/convertpsl.py | 36 |
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() |