-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathconverter.py
More file actions
28 lines (22 loc) · 993 Bytes
/
converter.py
File metadata and controls
28 lines (22 loc) · 993 Bytes
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
import sys
import re
def convert_list(input_filepath, output_filepath):
with open(input_filepath, 'r') as source_file, open(output_filepath, 'w') as target_file:
pattern_server = r'server='
pattern_bracket = r'['
old_dns = r'/114.114.114.114'
new_dns = r'/]h3://dns.alidns.com/dns-query'
for line in source_file:
converted_line = re.sub(pattern_server, pattern_bracket, line)
final_line = re.sub(old_dns, new_dns, converted_line)
target_file.write(final_line)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python converter.py <input_file>")
sys.exit(1)
input_filepath = sys.argv[1]
input_filename = input_filepath.split('/')[-1]
input_filename = input_filename.split('.')[0]
output_filename = f'{input_filename}_AdGuard.conf'
output_filepath = f'./{output_filename}'
convert_list(input_filepath, output_filepath)