-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (48 loc) · 1.66 KB
/
main.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
import requests
DIRECT = "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt"
PROXY = "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/proxy-list.txt"
APPLECN = "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/apple-cn.txt"
TODIRECTADDR = "-**DIRECT**-"
TOPROXYADDR = "-**PROXYADDR**-"
class site:
def __init__(self, raw):
self.raw = raw
if not len(raw):
self.raw = ''
if self.raw.startswith('full:'):
self.type = 'full'
self.domain = self.raw[5:]
elif self.raw.startswith('regexp:'):
self.type = 'regexp'
self.domain = self.raw[7:]
else:
self.type = 'domain'
self.domain = self.raw
def adg_dump(self, to_direct):
if not self.type == 'regexp':
return f'[/{self.domain}/]{TODIRECTADDR if to_direct else TOPROXYADDR}\n'
return None
def clash_dump(self, ):
pass
def get(path):
res = requests.get(path)
reslist = res.text.split('\n') if res.ok else []
complist = []
for domain in reslist:
if not len(domain):
continue
complist.append(site(domain))
return complist
if __name__ == '__main__':
directlist = list(set(get(DIRECT) + get(APPLECN)))
proxylist = get(PROXY)
with open('adg1.txt', 'w', encoding='UTF-8') as f:
for line in directlist:
line = line.adg_dump(True)
if line:
f.write(line)
for line in proxylist:
line = line.adg_dump(False)
if line:
f.write(line)
f.close()