2020-10-19 06:55:57 +00:00
|
|
|
#!/usr/bin/env python
|
2022-01-03 11:58:48 +00:00
|
|
|
# lint: pylint
|
2021-10-03 13:12:09 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2022-01-03 11:40:06 +00:00
|
|
|
"""This script saves `Ahmia's blacklist`_ for onion sites.
|
2020-10-19 06:55:57 +00:00
|
|
|
|
2022-01-03 11:40:06 +00:00
|
|
|
Output file: :origin:`searx/data/ahmia_blacklist.txt` (:origin:`CI Update data
|
|
|
|
... <.github/workflows/data-update.yml>`).
|
|
|
|
|
|
|
|
.. _Ahmia's blacklist: https://ahmia.fi/blacklist/
|
|
|
|
|
|
|
|
"""
|
2023-02-10 12:40:12 +00:00
|
|
|
# pylint: disable=use-dict-literal
|
2020-10-19 06:55:57 +00:00
|
|
|
|
|
|
|
import requests
|
2024-03-10 14:33:23 +00:00
|
|
|
from searx.data import data_dir
|
2020-10-19 06:55:57 +00:00
|
|
|
|
2024-03-10 14:33:23 +00:00
|
|
|
DATA_FILE = data_dir / 'ahmia_blacklist.txt'
|
2020-10-19 06:55:57 +00:00
|
|
|
URL = 'https://ahmia.fi/blacklist/banned/'
|
|
|
|
|
|
|
|
|
|
|
|
def fetch_ahmia_blacklist():
|
|
|
|
resp = requests.get(URL, timeout=3.0)
|
|
|
|
if resp.status_code != 200:
|
2023-02-10 12:40:12 +00:00
|
|
|
# pylint: disable=broad-exception-raised
|
2024-03-10 14:33:23 +00:00
|
|
|
raise Exception("Error fetching Ahmia blacklist, HTTP code " + resp.status_code) # type: ignore
|
2022-01-03 11:58:48 +00:00
|
|
|
return resp.text.split()
|
2020-10-19 06:55:57 +00:00
|
|
|
|
|
|
|
|
2022-01-03 11:40:06 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
blacklist = fetch_ahmia_blacklist()
|
2024-03-10 14:33:23 +00:00
|
|
|
blacklist.sort()
|
|
|
|
with DATA_FILE.open("w", encoding='utf-8') as f:
|
2022-01-03 11:40:06 +00:00
|
|
|
f.write('\n'.join(blacklist))
|