import os
import datetime
import argparse
import sys
import schedule
from loguru import logger
# TODO 发送钉钉消息
# TODO schedulerjob,定时每天几点执行
# 创建解析对象 description脚本描述
parser = argparse.ArgumentParser(description='直播时长按次整理统计脚本')
# 向该对象中添加你要关注的命令行参数和选项
parser.add_argument('-d', '--db_flag', help='数据库标志字符串', type=str, choices=['dev', 'test', 'pro'])
parser.add_argument('-u', '--user_id', help='用户ID字符串', type=str, default=None)
# 进行解析
args = parser.parse_args()
logger.info(f"args = {args}")
db_flag = args.db_flag
user_id = args.user_id
logger.info(f"db_flag = {db_flag} | user_id = {user_id}")
this_file_path = sys.argv[0]
this_log_file_path = os.path.join('./logs', this_file_path.split('/')[-1].split('.')[0] + f'_{db_flag}.log')
logger.add(this_log_file_path)
logger.info(f"this_log_file_path = {this_log_file_path}")
def do_something(db_flag, user_id):
logger.info(
f"do_something AT: {datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')} | db_flag = {db_flag} | user_id = {user_id}")
schedule.every().day.at("19:22").do(do_something, db_flag, user_id) # 每天定时n点运行
while True:
schedule.run_pending() # run_pending:运行所有可以运行的任务
# 启动方法: nohup python file.py --db_flag test --user_id user_1 &
argpare - 模板
最新推荐文章于 2023-01-05 10:55:50 发布