aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorresistance <resistance@noreply.codeberg.org>2020-08-04 04:33:39 +0200
committerresistance <resistance@noreply.codeberg.org>2020-08-04 04:33:39 +0200
commit449b4a0c56d45cee4c3cc21b17a6de49ceac0301 (patch)
treeba9e66fa95fd2c0e193dedbb3b5e1659182150d0
parentf3448abbea47b97ab5567aec89684a160d733a3b (diff)
parente868e5f52dc6d87bbfd76e466321fb0189889756 (diff)
downloadcloudflare-tor-449b4a0c56d45cee4c3cc21b17a6de49ceac0301.tar.lz
cloudflare-tor-449b4a0c56d45cee4c3cc21b17a6de49ceac0301.tar.xz
cloudflare-tor-449b4a0c56d45cee4c3cc21b17a6de49ceac0301.zip
PR 79
-rw-r--r--tool/anti-cf_filter_adblock/generate.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tool/anti-cf_filter_adblock/generate.py b/tool/anti-cf_filter_adblock/generate.py
new file mode 100644
index 00000000..680e26fd
--- /dev/null
+++ b/tool/anti-cf_filter_adblock/generate.py
@@ -0,0 +1,48 @@
+import glob
+import getopt
+import os
+import sys
+
+print("Anti-CF filter compiler for Adblock Plus/uBlock Origin/etc. v1.0")
+print("Licensed under CC0 1.0")
+print("")
+#functions
+def progress(value, filename):
+ sys.stdout.write('\033[2K\033[1G') #wipe the line before printing
+ sys.stdout.write("Compiling rules [%s] %s" % ("{:,}".format(value), filename))
+ sys.stdout.flush()
+
+opts, argv = getopt.getopt(sys.argv[1:], "o:d:")
+
+def process(outputf, inputd):
+ if not os.path.isdir(inputd):
+ print("Input not directory");
+ sys.exit(1)
+
+ with open(outputf, 'a') as outfile:
+ rulescom = 0 #counter for counting how much rules compiled
+
+ files = glob.glob(os.path.join(inputd, "*.txt")) #filter out anything but txt files
+
+ for f in files:
+ with open(f) as ruleso:
+ for line in ruleso:
+ outfile.write("||{}^$all\n".format(line.rstrip())) #this does the job
+ rulescom = rulescom + 1
+ progress(rulescom, f)
+
+
+
+if len(sys.argv) < 5: #check if theres argv
+ print("Usage: generate.py -o <output file> -d <input directory>")
+ print("Example: generate.py -o filter.txt -d ../../cloudflare_users/domains/")
+ sys.exit(1)
+
+#argv parsing
+for k, v in opts:
+ if k == '-o':
+ outputfile = v
+ if k == '-d':
+ inputdirectory = v
+
+process(outputfile, inputdirectory)