-
Notifications
You must be signed in to change notification settings - Fork 268
/
update.py
executable file
·61 lines (51 loc) · 1.39 KB
/
update.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
#!/usr/bin/env python3
import json
import os
import sys
if sys.version_info < (3,4):
import urllib2 as urlR
else:
import urllib.request as urlR
def Get_host(url):
if sys.version_info < (3,4):
data = urlR.urlopen(url).read()
else:
data = urlR.urlopen(url).read().decode()
dict_data = {}
with open("./data/tmp",'w') as f:
f.write(data)
with open("./data/tmp",'r') as f:
for line in f:
if len(line) > 4 and line[0:1] != '#' and '\n' and '\r' and '\r\n':
linedata = line.split()
if len(linedata) >= 2:
dict_data[linedata[1]] = linedata[0]
os.remove("./data/tmp")
return dict_data
def Update_record(data):
print ("Starting hosts updating...")
with open("./data/rpz.json",'w') as f:
json.dump(data, f)
print ("success! hosts have done ! ")
def GetWildcardsrcd(url):
print ("Starting wrcd updating...")
data = urlR.urlopen(url).read().decode()
with open("./data/wrcd.json",'w') as f:
f.write(data)
print ("success! wrcd have done ! ")
def main():
with open ("./conf/hosts_repository_config.json",'r') as d:
dict_config = json.load(d)
dict_host={}
for key1 in dict_config:
if key1 == "hosts":
for key2 in dict_config[key1]:
url = dict_config[key1][key2]
dict_data = Get_host(url)
dict_host.update( dict_data )
Update_record(dict_host)
elif key1 == "wrcd":
url = dict_config[key1]
GetWildcardsrcd(url)
if __name__ == '__main__':
main()