From f96e50055415db53f5ba284eee41ef8c7ce70d68 Mon Sep 17 00:00:00 2001 From: Tommy <4850853+wx00@users.noreply.github.com> Date: Mon, 28 Dec 2020 04:01:31 +0800 Subject: [PATCH] add abp/autoproxy format (resolve R0uter/gfw_domain_whitelist#23) --- convert-abp-format.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 convert-abp-format.py diff --git a/convert-abp-format.py b/convert-abp-format.py new file mode 100644 index 0000000..47ede93 --- /dev/null +++ b/convert-abp-format.py @@ -0,0 +1,42 @@ +from argparse import ArgumentParser + +from main import reformat, get_online_list + + +ABP_ALLOW_FMT = '||{}\n' + + +def parse_args(): + parser = ArgumentParser() + parser.add_argument( + '-i', + '--input', + dest='input', + default='accelerated-domains.china.conf', + help='path to whitelist', + ) + parser.add_argument( + '-o', + '--output', + dest='output', + default='whitelist.txt', + help='path to output autoproxy rule file', + ) + return parser.parse_args() + +def main(): + args = parse_args() + try: + with open(args.input, 'r', encoding='utf8') as fp: + result = reformat(fp, ABP_ALLOW_FMT) + except IOError: + print('Unable to open rule file, trying to get online list...') + result = get_online_list(ABP_ALLOW_FMT) + + content = ''.join(result) + with open(args.output, mode='w', encoding='utf8') as fp: + fp.write(content) + print('Done!') + +if __name__ == '__main__': + main()