Skip to content

Commit

Permalink
add abp/autoproxy format (resolve R0uter#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
wx00 committed Dec 27, 2020
1 parent 089e938 commit f96e500
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions convert-abp-format.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit f96e500

Please sign in to comment.