summaryrefslogtreecommitdiff
path: root/utils/fetch_ahmia_blacklist.py
blob: 3e393edbe9e9861842784dee35978434701ccb56 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python

# This script saves Ahmia's blacklist for onion sites.
# More info in https://ahmia.fi/blacklist/

# set path
from sys import path
from os.path import realpath, dirname, join
path.append(realpath(dirname(realpath(__file__)) + '/../'))

#
import requests
from searx import searx_dir

URL = 'https://ahmia.fi/blacklist/banned/'


def fetch_ahmia_blacklist():
    resp = requests.get(URL, timeout=3.0)
    if resp.status_code != 200:
        raise Exception("Error fetching Ahmia blacklist, HTTP code " + resp.status_code)
    else:
        blacklist = resp.text.split()
        return blacklist


def get_ahmia_blacklist_filename():
    return join(join(searx_dir, "data"), "ahmia_blacklist.txt")


blacklist = fetch_ahmia_blacklist()
with open(get_ahmia_blacklist_filename(), "w") as f:
    f.write('\n'.join(blacklist))