modify scripts
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
import json
|
||||
import time
|
||||
import csv
|
||||
import sys
|
||||
import argparse
|
||||
import logging
|
||||
from functools import partial
|
||||
@ -9,6 +10,13 @@ import config
|
||||
import sqlite_utils as db_tools
|
||||
import iafd_scraper as scraper
|
||||
import utils
|
||||
from pathlib import Path
|
||||
|
||||
# 添加 src 目录到路径
|
||||
root_dir = str(Path(__file__).resolve().parent.parent.parent)
|
||||
sys.path.append(root_dir)
|
||||
from src.monitor.scheduler import CommandScheduler
|
||||
from src.utils.utils import pretty_print_json
|
||||
|
||||
config.setup_logging()
|
||||
|
||||
@ -389,6 +397,11 @@ def fetch_movies_detail():
|
||||
def reset_actor_movie_cnt():
|
||||
db_tools.reset_actor_movies()
|
||||
|
||||
def check_task_status():
|
||||
# 命令行参数处理
|
||||
result = db_tools.get_statics()
|
||||
pretty_print_json(result)
|
||||
|
||||
# 建立缩写到函数的映射
|
||||
function_map = {
|
||||
"astro": fetch_performers_by_astro,
|
||||
@ -399,6 +412,7 @@ function_map = {
|
||||
"performers": fetch_performers_detail,
|
||||
"movies" : fetch_movies_detail,
|
||||
"reset_mv" : reset_actor_movie_cnt,
|
||||
"check" : check_task_status,
|
||||
}
|
||||
|
||||
# 主函数
|
||||
@ -415,6 +429,10 @@ def main(cmd, args_debug, args_force, args_skip_local):
|
||||
global skip_local
|
||||
skip_local = args_skip_local
|
||||
|
||||
if cmd.lower() == 'check':
|
||||
check_task_status()
|
||||
return None
|
||||
|
||||
# 开启任务
|
||||
task_id = db_tools.insert_task_log()
|
||||
if task_id is None:
|
||||
@ -423,6 +441,16 @@ def main(cmd, args_debug, args_force, args_skip_local):
|
||||
|
||||
logging.info(f'running task. id: {task_id}, debug: {debug}, force: {force}, cmd: {cmd}')
|
||||
|
||||
# 要执行的Shell命令(示例)
|
||||
shell_command = "cd ~/projects/resources/src/monitor; chmod u+x ./run.sh; ./run.sh iafd"
|
||||
|
||||
# 创建命令调度器(30分钟执行一次)
|
||||
scheduler = CommandScheduler(
|
||||
command=shell_command,
|
||||
interval=10 if debug else 1800
|
||||
)
|
||||
scheduler.run_periodically()
|
||||
|
||||
# 执行指定的函数
|
||||
if cmd:
|
||||
function_names = args.cmd.split(",") # 拆分输入
|
||||
@ -444,6 +472,8 @@ def main(cmd, args_debug, args_force, args_skip_local):
|
||||
logging.info(f'all process completed!')
|
||||
db_tools.finalize_task_log(task_id)
|
||||
|
||||
scheduler.stop()
|
||||
|
||||
# TODO:
|
||||
# 1, 演员列表中的影片数量,与电影列表中聚合出来的影片数量,可能不同。一个原因是某个影片有多个导演,且导演又兼了演员。比如:
|
||||
# https://www.iafd.com/title.rme/id=0f79d81f-25ff-40d1-967a-24b99f03b79a
|
||||
|
||||
@ -1034,6 +1034,64 @@ def finalize_task_log(task_id):
|
||||
except sqlite3.Error as e:
|
||||
logging.error(f"任务 {task_id} 结束失败: {e}")
|
||||
|
||||
def get_statics2():
|
||||
result={}
|
||||
|
||||
try:
|
||||
# 获取 performers、studios 等表的最终行数
|
||||
cursor.execute("SELECT COUNT(*) FROM iafd_performers")
|
||||
result['iafd_actors'] = cursor.fetchone()[0]
|
||||
|
||||
cursor.execute("SELECT COUNT(*) FROM iafd_performers where is_full_data=1")
|
||||
result['act_full'] = cursor.fetchone()[0]
|
||||
|
||||
cursor.execute("SELECT COUNT(*) FROM iafd_movies")
|
||||
result['movies'] = cursor.fetchone()[0]
|
||||
|
||||
cursor.execute("SELECT COUNT(*) FROM iafd_movies where is_full_data=1")
|
||||
result['mov_full'] = cursor.fetchone()[0]
|
||||
|
||||
cursor.execute("SELECT COUNT(*) FROM iafd_distributors")
|
||||
result['dist'] = cursor.fetchone()[0]
|
||||
|
||||
cursor.execute("SELECT COUNT(*) FROM iafd_studios")
|
||||
result['stu'] = cursor.fetchone()[0]
|
||||
|
||||
except sqlite3.Error as e:
|
||||
logging.error(f"query failed: {e}")
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def get_statics():
|
||||
try:
|
||||
# 使用单个SQL查询获取所有统计数据
|
||||
cursor.execute("""
|
||||
SELECT
|
||||
(SELECT COUNT(*) FROM iafd_performers) AS iafd_actors,
|
||||
(SELECT COUNT(*) FROM iafd_performers WHERE is_full_data=1) AS act_full,
|
||||
(SELECT COUNT(*) FROM iafd_movies) AS movies,
|
||||
(SELECT COUNT(*) FROM iafd_movies WHERE is_full_data=1) AS mov_full,
|
||||
(SELECT COUNT(*) FROM iafd_distributors) AS dist,
|
||||
(SELECT COUNT(*) FROM iafd_studios) AS stu
|
||||
""")
|
||||
|
||||
# 获取查询结果
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
return {}
|
||||
|
||||
# 手动定义列名(与SQL中的AS别名保持一致)
|
||||
#columns = ['iafd_actors', 'act_full', 'movies', 'mov_full', 'dist', 'stu']
|
||||
columns = [desc[0] for desc in cursor.description]
|
||||
|
||||
# 将元组结果转换为字典
|
||||
return dict(zip(columns, row))
|
||||
|
||||
except sqlite3.Error as e:
|
||||
logging.error(f"查询失败: {e}")
|
||||
return {}
|
||||
|
||||
if __name__ == "__main__":
|
||||
check_and_create_stat_table()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user