update_ahmia_blacklist.py 741 B

12345678910111213141516171819202122232425262728293031
  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 os.path import join
  6. import requests
  7. from searx import searx_dir
  8. URL = 'https://ahmia.fi/blacklist/banned/'
  9. def fetch_ahmia_blacklist():
  10. resp = requests.get(URL, timeout=3.0)
  11. if resp.status_code != 200:
  12. raise Exception("Error fetching Ahmia blacklist, HTTP code " + resp.status_code)
  13. else:
  14. blacklist = resp.text.split()
  15. return blacklist
  16. def get_ahmia_blacklist_filename():
  17. return join(join(searx_dir, "data"), "ahmia_blacklist.txt")
  18. blacklist = fetch_ahmia_blacklist()
  19. with open(get_ahmia_blacklist_filename(), "w") as f:
  20. f.write('\n'.join(blacklist))