forked from R0uter/gfw_domain_whitelist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add abp/autoproxy format (resolve R0uter#23)
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |