# -*- coding: utf-8 -*-
# @Author: wangkun
# @Time: 2023/3/7
import argparse
import os
import sys
import time

sys.path.append(os.getcwd())
from common.common import Common
from scheduling.scheduling_main.crawler_scheduling import Scheduling


class WriteTask:
    @classmethod
    def write_task(cls, log_type, crawler, env):
        Common.logger(log_type, crawler).info("开始读取爬虫任务，写入Redis")
        Scheduling.write_redis(log_type=log_type, crawler=crawler, env=env)
        Common.logger(log_type, crawler).info("写入Redis完成")
        Common.del_logs(log_type, crawler)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()  ## 新建参数解释器对象
    parser.add_argument('--log_type', default='follow', type=str, )  ## 添加参数,注明参数类型
    parser.add_argument('--crawler', default='youtube')  ## 添加参数
    parser.add_argument('--env', default='dev')  ## 添加参数
    # parser.add_argument('--machine')  ## 添加参数
    args = parser.parse_args()  ### 参数赋值，也可以通过终端赋值
    # print(args)
    WriteTask.write_task(
        log_type=args.log_type,
        crawler=args.crawler,
        env=args.env,
    )
