sql_help.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import os
  2. import sys
  3. from datetime import datetime
  4. sys.path.append(os.getcwd())
  5. from common.mysql_db import MysqlHelper
  6. class sqlCollect():
  7. @classmethod
  8. def get_channle_id(cls, pq_id):
  9. """
  10. 从数据库表中读取 id
  11. """
  12. sql = f"""select v_id,channel from machine_making_data where pq_vid = %s limit 1"""
  13. data = MysqlHelper.get_values(sql, (pq_id,))
  14. if data:
  15. return data[0][0],data[0][1]
  16. else:
  17. return None, None
  18. @classmethod
  19. def insert_pj_video_data(cls, user_video_id: str, channel: str):
  20. current_time = datetime.now()
  21. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  22. insert_sql = f"""INSERT INTO pj_video_data (task_name, mark_name,user_video_id,channel,data_time) values ("{user_video_id}", "{channel}", "{user_video_id}", "{channel}", '{formatted_time}')"""
  23. MysqlHelper.update_values(
  24. sql=insert_sql
  25. )
  26. @classmethod
  27. def select_pj_video_data(cls, user_video_id):
  28. """
  29. 从数据库表中读取 id
  30. """
  31. sql = f"""select user_video_id from pj_video_data where user_video_id = %s limit 1"""
  32. data = MysqlHelper.get_values(sql, (user_video_id,))
  33. if data:
  34. return True
  35. else:
  36. return False