Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # convert adblock ruleset into polipo-forbidden format
- if __name__ == "__main__":
- import os
- import sys
- import re
- if len(sys.argv) == 1:
- sys.exit("Usage: %s <adblockrules>" % os.path.basename(sys.argv[0]))
- if not os.path.exists(sys.argv[1]):
- sys.exit("The rules file (%s) doesn't exist" % sys.argv[1])
- fhandle = file(sys.argv[1])
- lines = fhandle.readlines()
- fhandle.close()
- dollar_re = re.compile("(.*?)\$.*")
- for line in lines:
- if line:
- if (line[0] in ("[", "!", "~", "#", "@") or
- line.startswith("/adverti") or
- "##" in line):
- continue
- line = dollar_re.sub(r"\1", line)
- # line = line.replace("|http://", "")
- line = line.replace("|", "")
- line = line.replace("||", "")
- line = line.replace(".", r"\.")
- line = line.replace("*", ".*")
- line = line.replace("?", r"\?")
- line = line.replace("^", r"[\/:\.=&\?\+\-\ ]+")
- # line = line.replace("&", r"\&")
- # line = line.replace("+", r"\+")
- # line = line.replace("-", r"\-")
- # line = line.replace(";", r"\;")
- # line = line.replace("=", r"\=")
- # line = line.replace("/", r"\/")
- print(line.strip())
- print("")
- #############
- # START NOTES
- #############
- ## Reference:
- ## <https://sites.google.com/site/monkeesage/files/>
- ## Example:
- ## wget https://fanboy.co.nz/r/fanboy-ultimate.txt
- ## python2 adblock2polipo.py fanboy-ultimate.txt > fanboy-ultimate.polipoid
- ###########
- # END NOTES
- ###########
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement