forked from guodong2005/hosts-for-working-hard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen.py
executable file
·61 lines (47 loc) · 1.58 KB
/
gen.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/python3
import glob
from datetime import datetime
from expt import expt
ToIP="10.8.55.252"
TIMESTR = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
black=expt("black")
white=expt("white")
"""
print("#", "final result:")
for x in black:
print("#", "'%s'" % x)
"""
# For hosts
s = """# This file is auto generated by `expt.py` at %s, in https://github.com/zcmimi/hosts-for-working-hard.
# Any changes applied will be removed after next generating.
""" % TIMESTR
for x in black:
s += "%s %s\n" % (ToIP, x)
open("hosts", "w", encoding="utf-8").write(s)
# For plain
# s = """# This file is auto generated by `expt.py` at %s, in https://github.com/zcmimi/hosts-for-working-hard.
# # Any changes applied will be removed after next generating.
#
# """ % TIMESTR
# for x in black:
# s += "%s\n" % x
# open("black.list", "w", encoding="utf-8").write(s)
open("black.list", "w", encoding="utf-8").write("\n".join(black))
open("white.list", "w", encoding="utf-8").write("\n".join(white))
# For mythware_classroom.xml
s = """<!-- This file is auto generated by `expt.py` at %s, in https://github.com/zcmimi/hosts-for-working-hard. -->
<!-- Any changes applied will be removed after next generating. -->
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<WebPolicy>
<White count="%d">
%s
</White>
<Black count="%d">
%s
</Black>
</WebPolicy>
""" % (TIMESTR,
len(white), "\n".join(['''<item url="%s" desc="" />''' % x for x in white]),
len(black), "\n".join(['''<item url="%s" desc="" />''' % x for x in black])
)
open("mythware_classroom.xml", "w", encoding="utf-8").write(s)