feat: 增加命令行参数解析,支持机器编号与后续任务控制,并根据数据库账号信息初始化DailymotionClient
This commit is contained in:
parent
a8e2ac1167
commit
8be9db943f
7
DB.py
7
DB.py
@ -211,6 +211,13 @@ class DBVidcon:
|
|||||||
continue
|
continue
|
||||||
return out
|
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)
|
@redis_retry(max_retries=3)
|
||||||
def push_l0(self, raws):
|
def push_l0(self, raws):
|
||||||
"""向 l0(加急)队列写入数据"""
|
"""向 l0(加急)队列写入数据"""
|
||||||
|
48
report.py
48
report.py
@ -1,10 +1,53 @@
|
|||||||
|
import argparse
|
||||||
import time
|
import time
|
||||||
from DB import DBVidcon, DBSA
|
from DB import DBVidcon, DBSA
|
||||||
|
from dump_keyword_title import parse_args
|
||||||
from report_video import DailymotionClient
|
from report_video import DailymotionClient
|
||||||
import logger
|
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()
|
db = DBVidcon()
|
||||||
d = DailymotionClient()
|
|
||||||
|
account = db.get_account_info(MACHINE_ID)
|
||||||
|
|
||||||
|
|
||||||
|
d = DailymotionClient(email=account['account'], password=account['password'])
|
||||||
|
|
||||||
k = {
|
k = {
|
||||||
"open": 1,
|
"open": 1,
|
||||||
@ -18,6 +61,7 @@ last_subsequent_run = 0
|
|||||||
MAIN_INTERVAL = 60 * 5 # 每 5 分钟执行一次
|
MAIN_INTERVAL = 60 * 5 # 每 5 分钟执行一次
|
||||||
SUBSEQUENT_INTERVAL = 60 * 60 # 每 60 分钟执行一次
|
SUBSEQUENT_INTERVAL = 60 * 60 # 每 60 分钟执行一次
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
|
|
||||||
@ -43,7 +87,7 @@ while True:
|
|||||||
time.sleep(60) # 出错延迟
|
time.sleep(60) # 出错延迟
|
||||||
|
|
||||||
|
|
||||||
if now - last_subsequent_run >= SUBSEQUENT_INTERVAL:
|
if now - last_subsequent_run >= SUBSEQUENT_INTERVAL and IsSubsequent:
|
||||||
last_subsequent_run = now
|
last_subsequent_run = now
|
||||||
subsequent_list = db.get_subsequent_report_video()
|
subsequent_list = db.get_subsequent_report_video()
|
||||||
if len(subsequent_list) > 0:
|
if len(subsequent_list) > 0:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user