-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate.py
34 lines (30 loc) · 1.33 KB
/
generate.py
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
34
import json, requests, datetime
from tqdm import tqdm
adlist = json.loads(open('adlist.json', 'r').read())
domains = []
filterList = ['0.0.0.0', '|', '^', '\n', '(', ')', '\\', '127.0.0.1']
startFilter = ('#', '.', '!', ':', ' ', ' ', '255.255.255.255')
for id, ad in enumerate(tqdm(adlist, desc="Downloading adlists", unit="domain")):
address = ad['address']
try:
r = requests.get(address, timeout=10)
if r.status_code == 200:
for i in r.text.split('\n'):
i = i.strip()
if i.startswith(startFilter):
continue
for filter in filterList:
i = i.replace(filter, '')
for reFilter in startFilter:
if i.startswith(reFilter):
i = i.replace(reFilter, '')
i = i.split('#', 1)[0].strip()
domains.append(i)
except Exception as e:
print(f"Error: {e}")
with open('blocklist.txt', 'w+', encoding='utf-8') as adblock:
adblock.write("# Generated by Pyenb\n")
adblock.write("# Check out https://github.com/Pyenb\n")
adblock.write(f"# Generated on {datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S')}\n")
for domain in tqdm(set(domains), desc="Writing to blocklist", unit="domain"):
adblock.write(f"{domain}\n")