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.

54 lines
1.4 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  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(description="Database operations")
  9. parser.add_argument(
  10. "-i", "--initialize", action="store_true", help="Reconstruct the whole database"
  11. )
  12. parser.add_argument(
  13. "-p", "--prune", action="store_true", help="Remove old entries from database"
  14. )
  15. parser.add_argument(
  16. "-b",
  17. "--prune-base",
  18. action="store_true",
  19. help="With --prune, only prune base rules "
  20. "(the ones added by ./feed_rules.py)",
  21. )
  22. parser.add_argument(
  23. "-s",
  24. "--prune-before",
  25. type=int,
  26. default=(int(time.time()) - 60 * 60 * 24 * 31 * 6),
  27. help="With --prune, only rules updated before "
  28. "this UNIX timestamp will be deleted",
  29. )
  30. parser.add_argument(
  31. "-r",
  32. "--references",
  33. action="store_true",
  34. help="DEBUG: Update the reference count",
  35. )
  36. args = parser.parse_args()
  37. if not args.initialize:
  38. DB = database.Database()
  39. else:
  40. if os.path.isfile(database.Database.PATH):
  41. os.unlink(database.Database.PATH)
  42. DB = database.Database()
  43. DB.enter_step("main")
  44. if args.prune:
  45. DB.prune(before=args.prune_before, base_only=args.prune_base)
  46. if args.references:
  47. DB.update_references()
  48. DB.save()