You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.7 KiB

import sys
import asyncio
from loguru import logger
from automaton import utils
from argparse import ArgumentParser
3 years ago
async def main():
3 years ago
parser = ArgumentParser('main.py')
# parser.add_argument('-v', dest='level', action='count', help='日志过滤等级,依次为 warning, info, debug, success')
subparsers = parser.add_subparsers(dest='method', help='模式选择')
3 years ago
3 years ago
method_list = subparsers.add_parser('list', help='列出所有课程和书籍')
method_list.add_argument('-d', '--detail', action='store_true', help='显示详细信息')
3 years ago
method_flash = subparsers.add_parser('flash', help='对选定的课程执行刷课')
3 years ago
target = method_flash.add_mutually_exclusive_group()
target.add_argument('-i', '--id', help='指定书籍ID')
target.add_argument('-c', '--current', action='store_true', help='限定为当前课程或书籍')
target.add_argument('-a', '--all', action='store_true', help='刷全部课程(慎用 除非你知道自己在进行什么操作)')
# method_flash.add_argument('-f', '--filter', help='任务过滤器,设置后只刷匹配的任务(尚未实现)') # Todo: 实现这个
args = parser.parse_args()
# logger.remove()
# logger.add(sys.stdout, level=['WARNING', 'INFO', 'DEBUG'][args.level or 0])
3 years ago
if args.method == 'list':
await utils.list_books(detail=args.detail)
elif args.method == 'flash':
if args.id:
await utils.flash_by_id(args.id)
elif args.current:
await utils.flash_current()
elif args.all:
await utils.flash_all()
else:
parser.print_help()
3 years ago
if __name__ == '__main__':
loop = asyncio.new_event_loop()
try:
loop.run_until_complete(main())
finally:
loop.close()