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.

47 lines
1.4KB

  1. #!/usr/bin/env python3
  2. import argparse
  3. import database
  4. import time
  5. import os
  6. if __name__ == '__main__':
  7. # Parsing arguments
  8. parser = argparse.ArgumentParser(
  9. description="Database operations")
  10. parser.add_argument(
  11. '-i', '--initialize', action='store_true',
  12. help="Reconstruct the whole database")
  13. parser.add_argument(
  14. '-p', '--prune', action='store_true',
  15. help="Remove old entries from database")
  16. parser.add_argument(
  17. '-b', '--prune-base', action='store_true',
  18. help="With --prune, only prune base rules "
  19. "(the ones added by ./feed_rules.py)")
  20. parser.add_argument(
  21. '-s', '--prune-before', type=int,
  22. default=(int(time.time()) - 60*60*24*31*6),
  23. help="With --prune, only rules updated before "
  24. "this UNIX timestamp will be deleted")
  25. parser.add_argument(
  26. '-r', '--references', action='store_true',
  27. help="DEBUG: Update the reference count")
  28. args = parser.parse_args()
  29. if not args.initialize:
  30. DB = database.Database()
  31. else:
  32. if os.path.isfile(database.Database.PATH):
  33. os.unlink(database.Database.PATH)
  34. DB = database.Database()
  35. DB.enter_step('main')
  36. if args.prune:
  37. DB.prune(before=args.prune_before, base_only=args.prune_base)
  38. if args.references:
  39. DB.update_references()
  40. DB.save()