-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate.py
executable file
·35 lines (28 loc) · 878 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 filter-item 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/dorjmi/nothingblock
! Version: {version}
! Expires: 7 days""".format(version=time_version)
# read item
filter_list = ''
item_dir = 'filter-item/'
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()