fetch_ahmia_blacklist.py 843 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env python
  2. # This script saves Ahmia's blacklist for onion sites.
  3. # More info in https://ahmia.fi/blacklist/
  4. # set path
  5. from sys import path
  6. from os.path import realpath, dirname, join
  7. path.append(realpath(dirname(realpath(__file__)) + '/../'))
  8. #
  9. import requests
  10. from searx import searx_dir
  11. URL = 'https://ahmia.fi/blacklist/banned/'
  12. def fetch_ahmia_blacklist():
  13. resp = requests.get(URL, timeout=3.0)
  14. if resp.status_code != 200:
  15. raise Exception("Error fetching Ahmia blacklist, HTTP code " + resp.status_code)
  16. else:
  17. blacklist = resp.text.split()
  18. return blacklist
  19. def get_ahmia_blacklist_filename():
  20. return join(join(searx_dir, "data"), "ahmia_blacklist.txt")
  21. blacklist = fetch_ahmia_blacklist()
  22. with open(get_ahmia_blacklist_filename(), "w") as f:
  23. f.write('\n'.join(blacklist))