demo.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/5/16
  4. import datetime
  5. import time
  6. from datetime import timedelta
  7. import requests
  8. import urllib3
  9. from main.common import Common
  10. from main.feishu_lib import Feishu
  11. proxies = {"http": None, "https": None}
  12. class Demo:
  13. # 查询视频详情的各项数据
  14. @classmethod
  15. def video_detail_info(cls, user_id, user_mid, video_id):
  16. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  17. headers = {
  18. "x-b3-traceid": "bd267349bf41b",
  19. "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
  20. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  21. "content-type": "application/json",
  22. "Accept-Encoding": "gzip,compress,br,deflate",
  23. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  24. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  25. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  26. "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
  27. }
  28. data = {
  29. "play_src": "1",
  30. "profile_id": int(user_id),
  31. "profile_mid": int(user_mid),
  32. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  33. "!400x400r/crop/400x400/interlace/1/format/jpg",
  34. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  35. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  36. "share_width": 625,
  37. "share_height": 500,
  38. "no_comments": True,
  39. "no_follow": True,
  40. "vid": video_id,
  41. "hot_l1_comment": True,
  42. "token": "90747742180aeb22c0fe3a3c6a38f3d9",
  43. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  44. "proj": "ma",
  45. "wx_ver": "8.0.20",
  46. "code_ver": "3.62.0",
  47. "log_common_params": {
  48. "e": [{
  49. "data": {
  50. "page": "dynamicSharePage"
  51. }
  52. }],
  53. "ext": {
  54. "brand": "iPhone",
  55. "device": "iPhone 11",
  56. "os": "iOS 14.7.1",
  57. "weixinver": "8.0.20",
  58. "srcver": "2.24.3",
  59. "net": "wifi",
  60. "scene": "1089"
  61. },
  62. "pj": "1",
  63. "pf": "2",
  64. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  65. }
  66. }
  67. try:
  68. urllib3.disable_warnings()
  69. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  70. video_title = r.json()["data"]["title"]
  71. video_id = r.json()["data"]["vid"]
  72. video_play_cnt = r.json()["data"]["play_pv"]
  73. video_duration = int(r.json()["data"]["du"])/1000
  74. video_url = r.json()["data"]["v_url"]
  75. video_send_time = r.json()["data"]["t"]
  76. print(r.text)
  77. print(f"video_title:{video_title}")
  78. print(f"video_id:{video_id}")
  79. print(f"video_play_cnt:{video_play_cnt}")
  80. print(f"video_duration:{video_duration}")
  81. print(f'video_send_time:{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time)/1000))}')
  82. print(f"video_url:{video_url}")
  83. except Exception as e:
  84. print(e)
  85. # 时间
  86. @classmethod
  87. def times(cls):
  88. # before_yesterday = (datetime.date.today() + timedelta(days=-2)).strftime("%Y/%m/%d %H:%M:%S")
  89. # before_yesterday = time.strptime(before_yesterday, "%Y/%m/%d %H:%M:%S")
  90. # before_yesterday = int(time.mktime(before_yesterday))
  91. # print(before_yesterday)
  92. # print(type(before_yesterday))
  93. # v_upload_time = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")[7][5]
  94. # v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y-%m-%d %H:%M:%S")))
  95. # print(v_upload_time)
  96. # print(int(time.time()) - v_send_time)
  97. pass
  98. # 微信号
  99. @classmethod
  100. def get_sheet(cls):
  101. hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "FEcuil")
  102. print(hour_sheet)
  103. print(hour_sheet[7][7])
  104. @classmethod
  105. def check_date(cls):
  106. date = Feishu.get_values_batch("hour", "xiaoniangao", "FEcuil")
  107. print(f'文档中L1:N1的日期:{date[0][11]}')
  108. today = datetime.datetime.now().strftime("%Y-%m-%d")
  109. print(f"today:{today}")
  110. Common.logger("hour").info("检查今日上升榜日期是否存在")
  111. if date[0][11] != today:
  112. # 插入3列 L1:N1,并写入日期和时间数据
  113. values = [[today], ["10:00", "15:00", "20:00"]]
  114. time.sleep(1)
  115. Feishu.insert_columns("hour", "xiaoniangao", "FEcuil", "COLUMNS", 11, 14)
  116. time.sleep(1)
  117. Feishu.update_values("hour", "xiaoniangao", "FEcuil", "L1:N2", values)
  118. time.sleep(1)
  119. Feishu.merge_cells("hour", "xiaoniangao", "FEcuil", "L1:N1")
  120. Common.logger("hour").info("插入今天日期成功")
  121. else:
  122. Common.logger("hour").info("今日上升榜日期已存在")
  123. if __name__ == "__main__":
  124. demo = Demo()
  125. # demo.video_detail_info("44838076", "116311065", "3941884615")
  126. # print("\n")
  127. # demo.video_detail_info("44767103", "116311065", "4167630382")
  128. # print("\n")
  129. # demo.video_detail_info("44264441", "329676836", "4505318929")
  130. # demo.times()
  131. # demo.video_detail_info("44615236", "460972177", "62a9965e000001609aa588ad")
  132. # demo.get_sheet()
  133. demo.check_date()