120 lines
3.6 KiB
Python
120 lines
3.6 KiB
Python
import argparse
|
|
import time
|
|
from DB import DBVidcon, DBSA
|
|
from report_video import DailymotionClient
|
|
from logger import logger
|
|
import requests
|
|
|
|
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()
|
|
|
|
|
|
def get_public_ip():
|
|
try:
|
|
response = requests.get("https://api.ipify.org?format=json", timeout=5)
|
|
return response.json().get("ip")
|
|
except requests.RequestException as e:
|
|
print("获取失败:", e)
|
|
return None
|
|
|
|
|
|
ip = get_public_ip()
|
|
logger.info(f"当前机器IP: {ip}, 机器编号: {MACHINE_ID}, 是否后续处理: {IsSubsequent}")
|
|
db = DBVidcon()
|
|
|
|
account = db.get_account_info(MACHINE_ID)
|
|
|
|
d = DailymotionClient(email=account['account'], password=account['password'])
|
|
|
|
k = {
|
|
"open": 1,
|
|
"solved": 2,
|
|
"awaiting your reply": 3,
|
|
}
|
|
|
|
last_main_run = 0
|
|
last_subsequent_run = 0
|
|
|
|
MAIN_INTERVAL = 60 * 5 # 每 5 分钟执行一次
|
|
SUBSEQUENT_INTERVAL = 60 * 60 # 每 60 分钟执行一次
|
|
|
|
d.test()
|
|
#
|
|
# while True:
|
|
# now = int(time.time())
|
|
#
|
|
# # 处理主流程
|
|
# if now - last_main_run >= MAIN_INTERVAL:
|
|
# last_main_run = now
|
|
# lis = db.item_report()
|
|
# if len(lis) > 0:
|
|
# for _, li in lis:
|
|
# print(li)
|
|
# logger.info(f"name:{li['name_title']},link:{li['link']} ")
|
|
# try:
|
|
# info, report_id, status, report_ts = d.process_ticket(li['name_title'], li['link'])
|
|
# subsequent_status = k.get(status, 1)
|
|
# db.update_fight_record_status(
|
|
# li['id'], report_id, 2, f"http://{ip}:5000/image/{info}",
|
|
# report_ts, subsequent_status, MACHINE_ID
|
|
# )
|
|
# db.flush()
|
|
# except Exception as e:
|
|
# logger.error(f"ID:{li['id']}, e:{e}")
|
|
# db.update_fight_record_status(li['id'], 0, 3, str(e), mid=MACHINE_ID)
|
|
# time.sleep(60) # 出错延迟
|
|
#
|
|
# if now - last_subsequent_run >= SUBSEQUENT_INTERVAL and IsSubsequent:
|
|
# last_subsequent_run = now
|
|
# subsequent_list = db.get_subsequent_report_video(MACHINE_ID)
|
|
# if len(subsequent_list) > 0:
|
|
# for li in subsequent_list:
|
|
# rs_id = li['id']
|
|
# r_id = li['report_id']
|
|
# logger.info(f"subsequent id:{rs_id},report_id:{r_id} ")
|
|
# # try:
|
|
# subsequent_status, info = d.report_follow_up(r_id)
|
|
# db.update_subsequent_status_by_id(
|
|
# rs_id, subsequent_status, f"http://{ip}:5000/image/{info}"
|
|
# )
|
|
# # except Exception as e:
|
|
# # logger.logger.error(f"ID:{rs_id}, e:{e}")
|
|
# # db.update_subsequent_status_by_id(rs_id, 1, str(e))
|
|
# time.sleep(5) # 避免频繁请求
|
|
# time.sleep(5)
|