sql_help.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import os
  2. import sys
  3. from datetime import datetime, timedelta
  4. sys.path.append(os.getcwd())
  5. from datetime import datetime
  6. from common import MysqlHelper
  7. class sqlCollect():
  8. """
  9. 视频信息写入库中
  10. """
  11. @classmethod
  12. def insert_task(cls, task_mark, video_id, mark, channel):
  13. current_time = datetime.now()
  14. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  15. 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}')"""
  16. MysqlHelper.update_values(
  17. sql=insert_sql
  18. )
  19. """
  20. 判断该任务id是否用过
  21. """
  22. @classmethod
  23. def is_used(cls, photo_id):
  24. sql = """
  25. SELECT photo_id
  26. FROM ks_category_video
  27. WHERE photo_id = %s
  28. """
  29. data = MysqlHelper.get_values(sql, (int(photo_id)))
  30. if len(data) == 0 or data == ():
  31. return True
  32. return False
  33. @classmethod
  34. def get_history_id(cls, channel, url):
  35. """
  36. 从数据库表中读取 id
  37. """
  38. sql = f"""select name_id from accounts where name = %s and platform = %s and useful = 1 limit 1"""
  39. data = MysqlHelper.get_values(sql, (url, channel))
  40. if data:
  41. return data[0][0]
  42. else:
  43. return False
  44. @classmethod
  45. def insert_ks_data(cls, account_name, target, channel):
  46. insert_sql = f"""INSERT INTO accounts (name, name_id, platform, useful) values ("{account_name}", "{target}", "{channel}", 1 )"""
  47. MysqlHelper.update_values(
  48. sql=insert_sql
  49. )