-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate.py
executable file
·35 lines (28 loc) · 873 Bytes
/
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
35
# combine all website into filter.txt.
import os
import re
import time
time_version = time.strftime("%Y.%m.%d.%H%M", time.localtime())
head = """\
[Adblock Plus 3.0]
! Title: NothingBlock filter
! Description: Block unnecessary web element to have 'Nothing more to take away'.
! Homepage: https://github.com/jinyuzu99/nothingblock
! Version: {version}
! Expires: 7 days""".format(version=time_version)
# read item
filter_list = ''
item_dir = 'website/'
item_list = sorted(os.listdir(item_dir))
for i in item_list:
file = open(item_dir + i, 'r')
filter_list = filter_list + file.read()
file.close()
# remove extra
filter_list = re.sub(' *', '', filter_list)
filter_list = re.sub('!.*', '', filter_list)
filter_list = re.sub('[\s]+', '\n', filter_list)
# write to filter.txt
filter = open("filter.txt", "w")
filter.write(head + filter_list)
filter.close()