demo.py 9.3 KB

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