get_vx_message.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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
  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('/Users/tzld/Desktop/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. for vx_message in vx_list:
  33. msg_type = vx_message[0]
  34. content = vx_message[1]
  35. channle = ''
  36. data = ''
  37. if msg_type == 'text':
  38. if "https://v.douyin.com" in content:
  39. channle = "douyin"
  40. data = douyinVideo.get_videoList(vx_message, channle)
  41. elif "https://v.ixigua.com" in content:
  42. channle = "xigua"
  43. data = xiguaVideo.get_videoList(vx_message, channle)
  44. elif "https://v.kuaishou.com" in content:
  45. channle = "kuaishou"
  46. data = kuaishouVideo.get_videoList(vx_message, channle)
  47. elif msg_type == 'link':
  48. if "mp.weixin.qq.com/s" in content:
  49. channle = "gongzhonghao"
  50. data = gongzhonghaoVdieo.get_videoList(vx_message, channle)
  51. elif msg_type == 'channels':
  52. if "nickname" in content:
  53. channle = "shipinhao"
  54. data = shipinhaoVdieo.get_videoList(vx_message, channle)
  55. else:
  56. print(f"该消息类型不做处理{msg_type}")
  57. break
  58. with open('/Users/tzld/Desktop/single_video_crawler/id', 'w') as file:
  59. file.write(str(id+1))
  60. # 获取当前时间
  61. current_time = datetime.now()
  62. formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
  63. if data == ' ':
  64. data = '无'
  65. values = [[
  66. vx_message[3],
  67. vx_message[2],
  68. channle,
  69. vx_message[4],
  70. str(vx_message),
  71. str(vx_message[5]),
  72. formatted_time,
  73. data
  74. ]]
  75. Feishu.insert_columns('video', "edd0a8", "ROWS", 1, 2)
  76. time.sleep(0.5)
  77. Feishu.update_values('video', "edd0a8", "A2:Z2", values)
  78. else:
  79. print("没数据哦")
  80. if __name__ == '__main__':
  81. url_list = VxMessage.vx_data()