コード例 #1
0
ファイル: cli.py プロジェクト: maocis/ybk
def do_quote(parser, args):
    setup_config(args)
    if args.qsubparser == 'realtime':
        parser = parser._actions[-1].choices['realtime']
        if args.sites:
            for site in args.sites:
                realtime(site)
        elif args.all:
            realtime_all()
        else:
            parser.print_help()
    elif args.qsubparser == 'history':
        parser = parser._actions[-1].choices['history']
        if args.sites:
            for site in args.sites:
                history(site, args.force)
        elif args.all:
            history_all()
        else:
            parser.print_help()
    else:
        parser.print_help()
コード例 #2
0
ファイル: cli.py プロジェクト: maocis/ybk
def do_cron(parser, args):
    setup_config(args)
    lockfile = '/tmp/ybk.cron.lock'
    path = pathlib.Path(lockfile)

    class doing(object):

        def __enter__(self):
            path.open('w').write('')

        def __exit__(self, type, value, traceback):
            if value:
                crawl_log.exception('出错啦')
            path.unlink()
            return True

    if not path.exists():
        with doing():
            crawl_all()

        now = datetime.utcnow() + timedelta(hours=8)
        with doing():
            if 9 <= now.hour <= 20:
                realtime_all()

        with doing():
            if now.hour == 6 and now.minute < 5:
                history_all()

        with doing():
            if 9 <= now.hour <= 20:
                # 生成所有人的历史收益记录
                ProfitLog.ensure_all_profits()

        # 更新所有交易账号的状态
        if now.hour == 22 and 30 <= now.minute <= 35:
            trade_account_all()
    else:
        crawl_log.info('已有cron在跑, 直接退出')