Generates a host list of first-party trackers for ad-blocking.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
984 B

3 years ago
  1. #!/usr/bin/env python3
  2. import database
  3. import argparse
  4. import sys
  5. FUNCTION_MAP = {
  6. 'zone': database.Database.set_zone,
  7. 'ip4network': database.Database.set_ip4network,
  8. 'asn': database.Database.set_asn,
  9. }
  10. if __name__ == '__main__':
  11. # Parsing arguments
  12. parser = argparse.ArgumentParser(
  13. description="TODO")
  14. parser.add_argument(
  15. 'type',
  16. choices=FUNCTION_MAP.keys(),
  17. help="Type of rule inputed")
  18. parser.add_argument(
  19. '-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
  20. help="List of domains domains to block (with their subdomains)")
  21. parser.add_argument(
  22. '-f', '--first-party', action='store_true',
  23. help="The input only comes from verified first-party sources")
  24. args = parser.parse_args()
  25. DB = database.Database(write=True)
  26. fun = FUNCTION_MAP[args.type]
  27. for rule in args.input:
  28. fun(DB, rule.strip(), is_first_party=args.first_party)
  29. DB.close()