get_vx_message.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. # @Time: 2024/03/27
  3. import datetime
  4. import os
  5. import sys
  6. import time
  7. from datetime import datetime
  8. sys.path.append(os.getcwd())
  9. from common import MysqlHelper, Feishu, Common
  10. from single_video.gongzhonghao.gongzhonghao_video import gongzhonghaoVdieo
  11. from single_video.shipinhao.shipinhao_author import shipinhaoVdieo
  12. from single_video.douyin.douyin_video import douyinVideo
  13. from single_video.kuaishou.kuaishou_video import kuaishouVideo
  14. from single_video.xigua.xigua_video import xiguaVideo
  15. class VxMessage():
  16. @classmethod
  17. def read_id(cls):
  18. with open('/root/single_video_crawler/id', 'r') as file:
  19. # 读取文件的全部内容
  20. content = file.read()
  21. return int(content)
  22. @classmethod
  23. def get_vx_message(cls, id):
  24. url_list = f"""select msg_type, content, nick_name, pq_uid, id, create_time from work_wx_kf_msg_info WHERE is_delete = 0 and id = {id} """
  25. url_list = MysqlHelper.get_values(url_list)
  26. return url_list
  27. @classmethod
  28. def vx_data(cls):
  29. id = cls.read_id()
  30. vx_list = cls.get_vx_message(id)
  31. if vx_list:
  32. print("开始执行")
  33. Common.logger().info(f"查询到数据{vx_list}")
  34. for vx_message in vx_list:
  35. msg_type = vx_message[0]
  36. content = vx_message[1]
  37. channle = ''
  38. data = ''
  39. if msg_type == 'text':
  40. if "https://v.douyin.com" in content:
  41. channle = "douyin"
  42. data = douyinVideo.get_videoList(vx_message, channle)
  43. elif "https://v.ixigua.com" in content:
  44. channle = "xigua"
  45. data = xiguaVideo.get_videoList(vx_message, channle)
  46. elif "https://v.kuaishou.com" in content:
  47. channle = "kuaishou"
  48. data = kuaishouVideo.get_videoList(vx_message, channle)
  49. elif msg_type == 'link':
  50. if "mp.weixin.qq.com/s" in content:
  51. channle = "gongzhonghao"
  52. data = gongzhonghaoVdieo.get_videoList(vx_message, channle)
  53. elif msg_type == 'channels':
  54. if "nickname" in content:
  55. channle = "shipinhao"
  56. data = shipinhaoVdieo.get_videoList(vx_message, channle)
  57. else:
  58. print(f"该消息类型不做处理{msg_type}")
  59. return
  60. with open('/root/single_video_crawler/id', 'w') as file:
  61. file.write(str(id+1))
  62. # 获取当前时间
  63. current_time = datetime.now()
  64. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  65. if data == ' ':
  66. data = '无'
  67. values = [[
  68. vx_message[3],
  69. vx_message[2],
  70. channle,
  71. vx_message[4],
  72. str(vx_message),
  73. str(vx_message[5]),
  74. formatted_time,
  75. data
  76. ]]
  77. Feishu.insert_columns('video', "edd0a8", "ROWS", 1, 2)
  78. time.sleep(0.5)
  79. Feishu.update_values('video', "edd0a8", "A2:Z2", values)
  80. else:
  81. print("数据库没有查询到数据")
  82. Common.logger().info("数据库没有查询到数据")
  83. if __name__ == '__main__':
  84. url_list = VxMessage.vx_data()