From 8be9db943f225efd82a08e05e3d9f6913bc7cbdd Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Thu, 19 Jun 2025 09:01:12 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E5=91=BD=E4=BB=A4?= =?UTF-8?q?=E8=A1=8C=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=9C=BA=E5=99=A8=E7=BC=96=E5=8F=B7=E4=B8=8E=E5=90=8E?= =?UTF-8?q?=E7=BB=AD=E4=BB=BB=E5=8A=A1=E6=8E=A7=E5=88=B6=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=95=B0=E6=8D=AE=E5=BA=93=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=88=9D=E5=A7=8B=E5=8C=96DailymotionClient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 7 +++++++ report.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/DB.py b/DB.py index 247b170..4c30ac7 100644 --- a/DB.py +++ b/DB.py @@ -211,6 +211,13 @@ class DBVidcon: continue return out + @mysql_retry() + def get_account_info(self, mid: str): + sql = "SELECT `account`,`password` FROM sh_site_accounts WHERE id = %s AND status=1 LIMIT 1" + self.cursor.execute(sql, (mid,)) + result = self.cursor.fetchone() + return result + @redis_retry(max_retries=3) def push_l0(self, raws): """向 l0(加急)队列写入数据""" diff --git a/report.py b/report.py index f9b8aaf..054dd35 100644 --- a/report.py +++ b/report.py @@ -1,10 +1,53 @@ +import argparse import time from DB import DBVidcon, DBSA +from dump_keyword_title import parse_args from report_video import DailymotionClient import logger + +MACHINE_ID = None +IsSubsequent = False + +def parse_args() -> argparse.Namespace: + global MACHINE_ID, IsSubsequent + + parser = argparse.ArgumentParser( + description="Configure worker settings." + ) + parser.add_argument( + "-m", "--machine-id", + type=int, + help=f"Machine identifier (default: {MACHINE_ID})" + ) + parser.add_argument( + "-s", "--IsSubsequent", + type=int, + help=f"Maximum concurrent workers (default: {IsSubsequent})" + ) + + args = parser.parse_args() + + if args.machine_id is not None: + MACHINE_ID = args.machine_id + + if args.IsSubsequent is not None: + if args.IsSubsequent <= 0: + IsSubsequent = False + else: + IsSubsequent = True + if MACHINE_ID is None: + raise ValueError("请指定机器编号") + return args + +parse_args() + db = DBVidcon() -d = DailymotionClient() + +account = db.get_account_info(MACHINE_ID) + + +d = DailymotionClient(email=account['account'], password=account['password']) k = { "open": 1, @@ -18,6 +61,7 @@ last_subsequent_run = 0 MAIN_INTERVAL = 60 * 5 # 每 5 分钟执行一次 SUBSEQUENT_INTERVAL = 60 * 60 # 每 60 分钟执行一次 + while True: now = int(time.time()) @@ -43,7 +87,7 @@ while True: time.sleep(60) # 出错延迟 - if now - last_subsequent_run >= SUBSEQUENT_INTERVAL: + if now - last_subsequent_run >= SUBSEQUENT_INTERVAL and IsSubsequent: last_subsequent_run = now subsequent_list = db.get_subsequent_report_video() if len(subsequent_list) > 0: