-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconvert.py
More file actions
36 lines (27 loc) · 1.3 KB
/
convert.py
File metadata and controls
36 lines (27 loc) · 1.3 KB
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
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
import urllib.request
import datetime
import os
uBO_filter_URL = 'https://raw.githubusercontent.com/List-KR/List-KR/master/filterslists/filterslist-uBlockOrigin.txt'
print("Filter update triggered at " + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
with urllib.request.urlopen(uBO_filter_URL) as response:
filter = response.read()
header = ''
sub_filters = []
filter_lines = filter.decode('utf-8').splitlines()
for line in filter_lines:
if line.startswith('!#include'):
sub_filters.append(line.split(" ")[1])
elif line.startswith('! '):
header += line + '\n'
if "Version: " in line:
with open('./dist/README.md', 'w', encoding="UTF-8") as f:
f.write(line.replace("! Version: ", ""))
flattened_filter = header + '\n'
for sub_filter in sub_filters:
with urllib.request.urlopen('https://raw.githubusercontent.com/List-KR/List-KR/master/filterslists/' + sub_filter) as response:
sub_filter_content = response.read().decode('utf-8')
flattened_filter += '!\n! Filter: ' + sub_filter + '\n!\n' + sub_filter_content + '\n'
with open('./dist/list-kr-flat.txt', 'w', encoding="UTF-8") as f:
f.write(flattened_filter)