demo.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/6/27
  4. import json
  5. import os
  6. import time
  7. from datetime import date
  8. import requests
  9. from main.common import Common
  10. from main.feishu_lib import Feishu
  11. class Demo:
  12. @classmethod
  13. def feishu(cls):
  14. value = Feishu.get_range_value("xiaoniangao", "monitor", "N7e2yI", "B4:B4")
  15. print(type(value))
  16. print(value)
  17. @classmethod
  18. def today(cls):
  19. today = date.today()
  20. print(today)
  21. value = Feishu.get_range_value("xiaoniangao", "monitor", "N7e2yI", "P1:P1")
  22. print(value)
  23. # print(Feishu.update_values("xiaoniangao", "monitor", "N7e2yI", "P1:P1", [[str(today)]]))
  24. @classmethod
  25. def lists(cls):
  26. list1 = [6445, 52077, 15333]
  27. list2 = [[x] for x in list1]
  28. print(list2)
  29. @classmethod
  30. def get_sheet(cls):
  31. xiaoniangao_sheet = Feishu.get_values_batch("xiaoniangao", "monitor", "N7e2yI")
  32. video_id = xiaoniangao_sheet[1][6]
  33. user_id = xiaoniangao_sheet[1][9]
  34. user_mid = xiaoniangao_sheet[1][10]
  35. print(video_id)
  36. print(user_id)
  37. print(user_mid)
  38. @classmethod
  39. def get_session(cls):
  40. # charles 抓包文件保存目录
  41. charles_file_dir = "../chlsfiles/"
  42. if int(len(os.listdir(charles_file_dir))) == 1:
  43. Common.logger("kanyikan").info("未找到chlsfile文件,等待60s")
  44. time.sleep(60)
  45. else:
  46. try:
  47. # 目标文件夹下所有文件
  48. all_file = sorted(os.listdir(charles_file_dir))
  49. # 获取到目标文件
  50. old_file = all_file[-1]
  51. # 分离文件名与扩展名
  52. new_file = os.path.splitext(old_file)
  53. # 重命名文件后缀
  54. os.rename(os.path.join(charles_file_dir, old_file),
  55. os.path.join(charles_file_dir, new_file[0] + ".txt"))
  56. with open(charles_file_dir + new_file[0] + ".txt", encoding='utf-8-sig', errors='ignore') as f:
  57. contents = json.load(f, strict=False)
  58. if "search.weixin.qq.com" in [text['host'] for text in contents]:
  59. for text in contents:
  60. if text["host"] == "search.weixin.qq.com" \
  61. and text["path"] == "/cgi-bin/recwxa/recwxagetunreadmessagecnt":
  62. sessions = text["query"].split("session=")[-1].split("&wxaVersion=")[0]
  63. if "&vid" in sessions:
  64. session = sessions.split("&vid")[0]
  65. return session
  66. elif "&offset" in sessions:
  67. session = sessions.split("&offset")[0]
  68. return session
  69. elif "&wxaVersion" in sessions:
  70. session = sessions.split("&wxaVersion")[0]
  71. return session
  72. elif "&limit" in sessions:
  73. session = sessions.split("&limit")[0]
  74. return session
  75. elif "&scene" in sessions:
  76. session = sessions.split("&scene")[0]
  77. return session
  78. elif "&count" in sessions:
  79. session = sessions.split("&count")[0]
  80. return session
  81. elif "&channelid" in sessions:
  82. session = sessions.split("&channelid")[0]
  83. return session
  84. elif "&subscene" in sessions:
  85. session = sessions.split("&subscene")[0]
  86. return session
  87. elif "&clientVersion" in sessions:
  88. session = sessions.split("&clientVersion")[0]
  89. return session
  90. elif "&sharesearchid" in sessions:
  91. session = sessions.split("&sharesearchid")[0]
  92. return session
  93. elif "&nettype" in sessions:
  94. session = sessions.split("&nettype")[0]
  95. return session
  96. elif "&switchprofile" in sessions:
  97. session = sessions.split("&switchprofile")[0]
  98. return session
  99. elif "&switchnewuser" in sessions:
  100. session = sessions.split("&switchnewuser")[0]
  101. return session
  102. else:
  103. return sessions
  104. else:
  105. Common.logger("kanyikan").info("未找到 session,10s后重新获取")
  106. time.sleep(10)
  107. cls.get_session()
  108. except Exception as e:
  109. Common.logger("kanyikan").exception("获取 session 异常,30s后重试:{}", e)
  110. time.sleep(30)
  111. cls.get_session()
  112. @classmethod
  113. def get_video_info(cls, video_id):
  114. url = "https://search.weixin.qq.com/cgi-bin/recwxa/recwxagetonevideoinfo?"
  115. param = {
  116. "session": cls.get_session(),
  117. "vid": video_id,
  118. "wxaVersion": "3.9.2",
  119. "channelid": "208201",
  120. "scene": "32",
  121. "subscene": "1089",
  122. "model": "iPhone 11<iPhone12,1>14.7.1",
  123. "clientVersion": "8.0.18",
  124. "sharesearchid": "447665862521758270",
  125. "sharesource": "-1"
  126. }
  127. r = requests.get(url=url, params=param)
  128. video_id = r.json()["data"]['vid']
  129. video_title = r.json()["data"]['title']
  130. play_cnt = r.json()["data"]["played_cnt"]
  131. shared_cnt = r.json()["data"]["shared_cnt"]
  132. if "items" not in r.json()["data"]["play_info"]:
  133. video_url = r.json()["data"]["play_info"][-1]["play_url"]
  134. # video_url = r.json()["data"]["play_info"]
  135. else:
  136. video_url = r.json()["data"]["play_info"]["items"][-1]["play_url"]
  137. # video_url = r.json()["data"]["play_info"]
  138. print(f"video_id:{video_id}")
  139. print(f"video_title:{video_title}")
  140. print(f"play_cnt:{play_cnt}")
  141. print(f"shared_cnt:{shared_cnt}")
  142. print(f"video_url:{video_url}")
  143. # response = {
  144. # 'data': {
  145. # 'collection_info': {
  146. # 'collectionid': 'mmsearchrecwxacollection_496906082_1641976100173',
  147. # 'episode_count': 0,
  148. # 'img': '',
  149. # 'latest_episode': 0,
  150. # 'size': 0,
  151. # 'title': ''
  152. # },
  153. # 'comment_cnt': 54,
  154. # 'composite_type': 0,
  155. # 'composite_video_info': {
  156. # 'first_composite_img_url': ''
  157. # },
  158. # 'cover_url': 'http://mmbiz.qpic.cn/wx_search/duc2TvpEgSTib1eic8eJ1MrictHrfvedFwfUGYhyjlJicpnrTrygHcSuTg/0',
  159. # 'duration': 210,
  160. # 'height': 1200,
  161. # 'isUGCVideo': True,
  162. # 'is_expose_comment': False,
  163. # 'is_following': False,
  164. # 'is_forbid_comment': False,
  165. # 'is_livereserve': False,
  166. # 'item_type': 16,
  167. # 'liked': False,
  168. # 'liked_cnt': 1865,
  169. # 'openid': 'oh_m45TTUoolLfj0x0vHl0QdlSw8',
  170. # 'owner_head_image': 'http://mmbiz.qpic.cn/wx_search/duc2TvpEgSRgbVcqh8gWWmQicsib3HJ97O6zfzwiazWMyIIzkKJxluhgQ/0',
  171. # 'play_icon_cover_url': 'http://mmbiz.qpic.cn/wx_search/Q3auHgzwzM6hiaHcSicmACTMfgzFdsLu77ovZnnx8MSLHhz2vYTxiaUfcrllqxW5t0bfNArKjOJBxw/0',
  172. # 'play_info': {
  173. # 'cdn_gif_url': '',
  174. # 'cdn_source_type': 4,
  175. # 'end_play_time_in_ms': 0,
  176. # 'video_api': '',
  177. # 'watermark_type': 0
  178. # },
  179. # 'played_cnt': 347350,
  180. # 'shared_cnt': 35463,
  181. # 'size': 0,
  182. # 'status': 10,
  183. # 'title': '太恶心了_现在的外卖,正在毁掉我们的下一代_Merge',
  184. # 'upload_time': 1647850532,
  185. # 'user_info': {
  186. # 'headimg_url': 'http://mmbiz.qpic.cn/wx_search/duc2TvpEgSRgbVcqh8gWWmQicsib3HJ97O6zfzwiazWMyIIzkKJxluhgQ/0',
  187. # 'nickname': '代替不了',
  188. # 'openid': 'oh_m45TTUoolLfj0x0vHl0QdlSw8'
  189. # },
  190. # 'vid': 'ugc_b42rvhr',
  191. # 'video_type': 1,
  192. # 'width': 720
  193. # },
  194. # 'errcode': 0,
  195. # 'msg': 'ok',
  196. # 'retcode': 0
  197. # }
  198. @classmethod
  199. def get_dir(cls):
  200. charles_file_dir = "../chlsfiles/"
  201. print(charles_file_dir)
  202. if __name__ == "__main__":
  203. demo = Demo()
  204. # demo.feishu()
  205. demo.today()
  206. # demo.lists()
  207. # demo.get_sheet()
  208. # demo.get_video_info("ugc_iqrmf5")
  209. # demo.get_dir()