import os import sys from datetime import datetime, timedelta sys.path.append(os.getcwd()) from datetime import datetime from common import MysqlHelper class sqlCollect(): """ 视频信息写入库中 """ @classmethod def insert_task(cls, task_mark, video_id, mark, channel): current_time = datetime.now() formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S") insert_sql = f"""INSERT INTO pj_video_data (task_name, used_video_id, mark_name, data_time, channel) values ('{task_mark}' ,'{video_id}','{mark}', '{formatted_time}', '{channel}')""" MysqlHelper.update_values( sql=insert_sql ) """ 判断该任务id是否用过 """ @classmethod def is_used(cls, photo_id): sql = """ SELECT photo_id FROM ks_category_video WHERE photo_id = %s """ data = MysqlHelper.get_values(sql, (int(photo_id))) if len(data) == 0 or data == (): return True return False @classmethod def get_history_id(cls, channel, url): """ 从数据库表中读取 id """ sql = f"""select name_id from accounts where name = %s and platform = %s and useful = 1 limit 1""" data = MysqlHelper.get_values(sql, (url, channel)) if data: return data[0][0] else: return False @classmethod def insert_ks_data(cls, account_name, target, channel): insert_sql = f"""INSERT INTO accounts (name, name_id, platform, useful) values ("{account_name}", "{target}", "{channel}", 1 )""" MysqlHelper.update_values( sql=insert_sql )