"""
@author: luojunhui
账号联想---账号搜索任务
"""
import traceback

from argparse import ArgumentParser
from datetime import datetime

from applications import bot
from coldStartTasks.crawler.weixin_account_association_crawler import AccountAssociationCrawler


def main():
    """
    账号联想---账号搜索任务
    :return:
    """
    parser = ArgumentParser()
    parser.add_argument("--run-date",
                        help="Run only once for date in format of %Y-%m-%d. \
                                If no specified, run as daily jobs.")
    args = parser.parse_args()

    if args.run_date:
        biz_date_str = args.run_date
    else:
        biz_date_str = datetime.today().strftime('%Y-%m-%d')
    try:
        biz_date = datetime.strptime(biz_date_str, "%Y-%m-%d")
        account_association_crawler = AccountAssociationCrawler()
        account_association_crawler.run_account_association(biz_date=biz_date)
    except Exception as e:
        bot(
            title="账号联想任务失败",
            detail={
                "error": str(e),
                "error_stack": traceback.format_exc()
            }
        )


if __name__ == '__main__':
    main()
