Generates a host list of first-party trackers for ad-blocking. https://hostfiles.frogeye.fr
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.

91 lines
2.5 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #!/usr/bin/env python3
  2. import database
  3. import argparse
  4. import sys
  5. if __name__ == "__main__":
  6. # Parsing arguments
  7. parser = argparse.ArgumentParser(
  8. description="Export the hostnames rules stored " "in the Database as plain text"
  9. )
  10. parser.add_argument(
  11. "-o",
  12. "--output",
  13. type=argparse.FileType("w"),
  14. default=sys.stdout,
  15. help="Output file, one rule per line",
  16. )
  17. parser.add_argument(
  18. "-f",
  19. "--first-party",
  20. action="store_true",
  21. help="Only output rules issued from first-party sources",
  22. )
  23. parser.add_argument(
  24. "-e",
  25. "--end-chain",
  26. action="store_true",
  27. help="Only output rules that are not referenced by any other",
  28. )
  29. parser.add_argument(
  30. "-r",
  31. "--rules",
  32. action="store_true",
  33. help="Output all kinds of rules, not just hostnames",
  34. )
  35. parser.add_argument(
  36. "-b",
  37. "--base-rules",
  38. action="store_true",
  39. help="Output base rules "
  40. "(the ones added by ./feed_rules.py) "
  41. "(implies --rules)",
  42. )
  43. parser.add_argument(
  44. "-d",
  45. "--no-dupplicates",
  46. action="store_true",
  47. help="Do not output rules that already match a zone/network rule "
  48. "(e.g. dummy.example.com when there's a zone example.com rule)",
  49. )
  50. parser.add_argument(
  51. "-x",
  52. "--explain",
  53. action="store_true",
  54. help="Show the chain of rules leading to one "
  55. "(and the number of references they have)",
  56. )
  57. parser.add_argument(
  58. "-c",
  59. "--count",
  60. action="store_true",
  61. help="Show the number of rules per type instead of listing them",
  62. )
  63. args = parser.parse_args()
  64. DB = database.Database()
  65. if args.count:
  66. assert not args.explain
  67. print(
  68. DB.count_records(
  69. first_party_only=args.first_party,
  70. end_chain_only=args.end_chain,
  71. no_dupplicates=args.no_dupplicates,
  72. rules_only=args.base_rules,
  73. hostnames_only=not (args.rules or args.base_rules),
  74. )
  75. )
  76. else:
  77. for domain in DB.list_records(
  78. first_party_only=args.first_party,
  79. end_chain_only=args.end_chain,
  80. no_dupplicates=args.no_dupplicates,
  81. rules_only=args.base_rules,
  82. hostnames_only=not (args.rules or args.base_rules),
  83. explain=args.explain,
  84. ):
  85. print(domain, file=args.output)