hour_list.py 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/5/16
  4. import datetime
  5. import time
  6. import requests
  7. import urllib3
  8. from main.common import Common
  9. from main.feishu_lib import Feishu
  10. proxies = {"http": None, "https": None}
  11. class HourList:
  12. # 今天的日期:年-月-日
  13. today = datetime.datetime.now().strftime("%Y-%m-%d")
  14. # 昨天
  15. yesterday = (datetime.date.today() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d")
  16. # 前天
  17. before_yesterday = (datetime.date.today() + datetime.timedelta(days=-2)).strftime("%Y-%m-%d")
  18. # 下载规则
  19. @staticmethod
  20. def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt):
  21. """
  22. 下载视频的基本规则
  23. :param d_duration: 时长
  24. :param d_width: 宽
  25. :param d_height: 高
  26. :param d_play_cnt: 播放量
  27. :param d_like_cnt: 点赞量
  28. :param d_share_cnt: 分享量
  29. :return: 满足规则,返回 True;反之,返回 False
  30. """
  31. if 600 >= int(float(d_duration)) >= 60:
  32. if int(d_width) >= 0 or int(d_height) >= 0:
  33. if int(d_play_cnt) >= 0:
  34. if int(d_like_cnt) >= 0:
  35. if int(d_share_cnt) >= 0:
  36. return True
  37. else:
  38. return False
  39. else:
  40. return False
  41. else:
  42. return False
  43. return False
  44. return False
  45. # 获取列表
  46. @classmethod
  47. def get_hour_list_feeds(cls):
  48. """
  49. 1.从列表获取视频,7 天内,播放量>=5000
  50. 2.时长 1-10min
  51. 3.每天10:00、15:00、20:00 把符合规则的视频,写入云文档
  52. https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  53. """
  54. url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
  55. headers = {
  56. "x-b3-traceid": "bd267349bf41b",
  57. "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
  58. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  59. "content-type": "application/json",
  60. "Accept-Encoding": "gzip,compress,br,deflate",
  61. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  62. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  63. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  64. "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
  65. }
  66. data = {
  67. "log_params": {
  68. "page": "discover_rec",
  69. "common": {
  70. "brand": "iPhone",
  71. "device": "iPhone 11",
  72. "os": "iOS 14.7.1",
  73. "weixinver": "8.0.20",
  74. "srcver": "2.24.2",
  75. "net": "wifi",
  76. "scene": 1089
  77. }
  78. },
  79. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
  80. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!80x80r/crop/80x80/interlace/1/format/jpg",
  81. "share_width": 625,
  82. "share_height": 500,
  83. "ext": {
  84. "fmid": 0,
  85. "items": {}
  86. },
  87. "app": "xng",
  88. "rec_scene": "discover_rec",
  89. "log_common_params": {
  90. "e": [{
  91. "data": {
  92. "page": "discoverIndexPage",
  93. "topic": "recommend"
  94. },
  95. "ab": {}
  96. }],
  97. "ext": {
  98. "brand": "iPhone",
  99. "device": "iPhone 11",
  100. "os": "iOS 14.7.1",
  101. "weixinver": "8.0.20",
  102. "srcver": "2.24.3",
  103. "net": "wifi",
  104. "scene": "1089"
  105. },
  106. "pj": "1",
  107. "pf": "2",
  108. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  109. },
  110. "refresh": False,
  111. "token": "90747742180aeb22c0fe3a3c6a38f3d9",
  112. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  113. "proj": "ma",
  114. "wx_ver": "8.0.20",
  115. "code_ver": "3.62.0"
  116. }
  117. try:
  118. urllib3.disable_warnings()
  119. r = requests.post(url=url, headers=headers, json=data, proxies=proxies, verify=False)
  120. if "data" not in r.json():
  121. Common.logger().warning("获取视频feeds错误:{}", r.text)
  122. elif "list" not in r.json()["data"]:
  123. Common.logger().warning("获取视频feeds无数据,休眠10s:{}", r.json()["data"])
  124. else:
  125. # 视频列表数据
  126. feeds = r.json()["data"]["list"]
  127. for i in range(len(feeds)):
  128. # 标题
  129. if "title" in feeds[i]:
  130. video_title = feeds[i]["title"].strip().replace("\n", "") \
  131. .replace("/", "").replace("\r", "").replace("#", "") \
  132. .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
  133. .replace(":", "").replace("*", "").replace("?", "") \
  134. .replace("?", "").replace('"', "").replace("<", "") \
  135. .replace(">", "").replace("|", "").replace(" ", "")
  136. Common.logger().info("标题:{}", video_title)
  137. else:
  138. video_title = ""
  139. Common.logger().info("当前视频无标题:{}", video_title)
  140. # 视频 ID
  141. if "vid" in feeds[i]:
  142. video_id = feeds[i]["vid"]
  143. Common.logger().info("视频ID:{}", video_id)
  144. else:
  145. video_id = ""
  146. Common.logger().info("当前视频无ID:{}", video_id)
  147. # 播放量
  148. if "play_pv" in feeds[i]:
  149. video_play_cnt = feeds[i]["play_pv"]
  150. Common.logger().info("视频播放量:{}", video_play_cnt)
  151. else:
  152. video_play_cnt = ""
  153. Common.logger().info("当前视频无播放量:{}", video_play_cnt)
  154. # 点赞量
  155. if "favor" in feeds[i]:
  156. video_like_cnt = feeds[i]["favor"]["total"]
  157. Common.logger().info("视频点赞量:{}", video_like_cnt)
  158. else:
  159. video_like_cnt = ""
  160. Common.logger().info("当前视频无点赞量:{}", video_like_cnt)
  161. # 分享量
  162. if "share" in feeds[i]:
  163. video_share_cnt = feeds[i]["share"]
  164. Common.logger().info("视频分享量:{}", video_share_cnt)
  165. else:
  166. video_share_cnt = ""
  167. Common.logger().info("当前视频无分享量:{}", video_share_cnt)
  168. # 评论量
  169. if "comment_count" in feeds[i]:
  170. video_comment_cnt = feeds[i]["comment_count"]
  171. Common.logger().info("视频评论数:{}", video_comment_cnt)
  172. else:
  173. video_comment_cnt = ""
  174. Common.logger().info("当前视频无评论:{}", video_comment_cnt)
  175. # 时长
  176. if "du" in feeds[i]:
  177. video_duration = int(feeds[i]["du"] / 1000)
  178. Common.logger().info("视频时长:{}秒", video_duration)
  179. else:
  180. video_duration = ""
  181. Common.logger().info("当前视频无时长:{}", video_duration)
  182. # 宽和高
  183. if "w" or "h" in feeds[i]:
  184. video_width = feeds[i]["w"]
  185. video_height = feeds[i]["h"]
  186. Common.logger().info("视频宽高:{}*{}", video_width, video_height)
  187. else:
  188. video_width = ""
  189. video_height = ""
  190. Common.logger().info("当前视频无宽高:{}{}", video_width, video_height)
  191. # 发布时间
  192. if "t" in feeds[i]:
  193. video_send_time = feeds[i]["t"]
  194. Common.logger().info(
  195. "视频发布时间:{}", time.strftime(
  196. "%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
  197. else:
  198. video_send_time = ""
  199. Common.logger().info("当前视频无发布时间:{}", video_send_time)
  200. # 用户名 / 头像
  201. if "user" in feeds[i]:
  202. user_name = feeds[i]["user"]["nick"].strip().replace("\n", "") \
  203. .replace("/", "").replace("快手", "").replace(" ", "") \
  204. .replace(" ", "").replace("&NBSP", "").replace("\r", "")
  205. head_url = feeds[i]["user"]["hurl"]
  206. Common.logger().info("用户名:{}", user_name)
  207. Common.logger().info("用户头像:{}", head_url)
  208. else:
  209. user_name = ""
  210. head_url = ""
  211. Common.logger().info("当前视频无用户名:{}", user_name)
  212. Common.logger().info("当前视频无用户头像:{}", head_url)
  213. # 用户 ID
  214. profile_id = feeds[i]["id"]
  215. # 用户 mid
  216. profile_mid = feeds[i]["user"]["mid"]
  217. # 视频封面
  218. if "url" in feeds[i]:
  219. cover_url = feeds[i]["url"]
  220. Common.logger().info("视频封面:{}", cover_url)
  221. else:
  222. cover_url = ""
  223. Common.logger().info("当前视频无视频封面:{}", cover_url)
  224. # 视频播放地址
  225. if "v_url" in feeds[i]:
  226. video_url = feeds[i]["v_url"]
  227. Common.logger().info("播放地址:{}", video_url)
  228. else:
  229. video_url = ""
  230. Common.logger().info("当前视频无播放地址:{}", video_url)
  231. # 过滤无效视频
  232. if video_title == "" or video_id == "" or video_duration == "" \
  233. or video_send_time == "" or user_name == "" or head_url == "" \
  234. or cover_url == "" or video_url == "":
  235. Common.logger().warning("无效视频")
  236. # 判断发布时间是否 > 7天
  237. elif int(time.time()) - int(video_send_time)/1000 > 604800:
  238. Common.logger().info("发布时间大于7天", video_title)
  239. # 判断播放量是否 > 5000
  240. elif int(video_play_cnt) < 5000:
  241. Common.logger().info("该视频7天内播放量<5000:{}", video_title)
  242. # 从云文档去重:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=onyBDH
  243. elif video_id in [j for i in Feishu.get_values_batch("xiaoniangao", "ba0da4") for j in i]:
  244. Common.logger().info("该视频已保存过:{}", video_title)
  245. else:
  246. Common.logger().info("该视频未下载,添加至feeds中:{}".format(video_title))
  247. # feeds工作表,插入空行
  248. time.sleep(1)
  249. Feishu.insert_columns("xiaoniangao", "ba0da4", "ROWS", 2, 3)
  250. # 获取当前时间
  251. get_feeds_time = int(time.time())
  252. # 看一看云文档,工作表中写入数据
  253. values = [[profile_id, profile_mid, video_id, video_title, user_name, video_url, time.strftime(
  254. "%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
  255. str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(get_feeds_time))),
  256. video_play_cnt]]
  257. # 等待 1s,防止操作云文档太频繁,导致报错
  258. time.sleep(1)
  259. Feishu.update_values("xiaoniangao", "ba0da4", "A3:I3", values)
  260. except Exception as e:
  261. Common.logger().error("获取小时榜视频列表异常:{}", e)
  262. # 检查是否有今日的上升榜日期
  263. @classmethod
  264. def check_hour_list_data(cls):
  265. # 判断J1单元格的日期是否为今天
  266. if Feishu.get_range_value("xiaoniangao", "ba0da4", "J1:J1")[0] != cls.today:
  267. # 插入3列 J1:L1,并写入日期和时间数据
  268. values = [[cls.today], ["10:00", "15:00", "20:00"]]
  269. Feishu.insert_columns("xiaoniangao", "ba0da4", "COLUMNS", 9, 12)
  270. Feishu.update_values("xiaoniangao", "ba0da4", "J1:L2", values)
  271. Feishu.merge_cells("xiaoniangao", "ba0da4", "J1:L1")
  272. Common.logger().info("插入今天日期成功")
  273. else:
  274. Common.logger().info("今日上升榜日期已存在")
  275. # 清除空行
  276. @classmethod
  277. def del_null_rows(cls, crawler, sheetid, startindex):
  278. """
  279. :params sheetid:工作表 ID
  280. :params startindex:从第几行开始清除
  281. """
  282. for i in range(int(startindex), len(Feishu.get_values_batch(crawler, sheetid)) + 1):
  283. time.sleep(1)
  284. Common.logger().info("正在检查第:{}行", i)
  285. # 删除空行
  286. if Feishu.get_range_value(crawler, sheetid, "A" + str(i) + ":" + "A" + str(i))[0] is None\
  287. and Feishu.get_range_value(crawler, sheetid, "B" + str(i) + ":" + "B" + str(i))[0] is None\
  288. and Feishu.get_range_value(crawler, sheetid, "C" + str(i) + ":" + "C" + str(i))[0] is None\
  289. and Feishu.get_range_value(crawler, sheetid, "D" + str(i) + ":" + "D" + str(i))[0] is None:
  290. Common.logger().info("当前第{}行为空行,删除", i)
  291. Feishu.dimension_range(crawler, sheetid, "ROWS", i, i)
  292. Common.logger().info("删除空行完成")
  293. # 更新小时榜数据
  294. @classmethod
  295. def update_hour_list_data(cls):
  296. """
  297. 更新小时榜数据
  298. """
  299. try:
  300. if len(Feishu.get_values_batch("xiaoniangao", "ba0da4")) == 2:
  301. Common.logger().info("当前工作表无数据")
  302. else:
  303. for i in range(3, len(Feishu.get_values_batch("xiaoniangao", "ba0da4"))+1):
  304. time.sleep(1)
  305. Common.logger().info("更新第:{}行视频信息", i)
  306. # 略过空行
  307. if Feishu.get_range_value("xiaoniangao", "ba0da4", "D" + str(i) + ":" + "D" + str(i))[0] is None\
  308. and Feishu.get_range_value("xiaoniangao", "ba0da4", "C"+str(i)+":"+"C"+str(i))[0] is None\
  309. and Feishu.get_range_value("xiaoniangao", "ba0da4", "A"+str(i)+":"+"A"+str(i))[0] is None:
  310. Common.logger().info("空行,略过")
  311. else:
  312. # 视频标题
  313. v_title = Feishu.get_range_value("xiaoniangao", "ba0da4", "D" + str(i) + ":" + "D" + str(i))[0]
  314. Common.logger().info("视频详情,video_title:{},{}", v_title, type(v_title))
  315. # 视频 ID
  316. v_id = Feishu.get_range_value("xiaoniangao", "ba0da4", "C" + str(i) + ":" + "C" + str(i))[0]
  317. Common.logger().info("视频详情,video_id:{},{}", v_id, type(v_id))
  318. # profile_id,用户 ID
  319. p_id = Feishu.get_range_value("xiaoniangao", "ba0da4", "A" + str(i) + ":" + "A" + str(i))[0]
  320. Common.logger().info("视频详情,profile_id:{},{}", p_id, type(p_id))
  321. # profile_mid
  322. p_mid = Feishu.get_range_value("xiaoniangao", "ba0da4", "B" + str(i) + ":" + "B" + str(i))[0]
  323. Common.logger().info("视频详情,profile_mid:{},{}", p_mid, type(p_mid))
  324. # 抓取时的播放量
  325. v_play_cnt = Feishu.get_range_value(
  326. "xiaoniangao", "ba0da4", "I" + str(i) + ":" + "I" + str(i))[0]
  327. Common.logger().info("视频详情,video_play_cnt:{},{}", v_play_cnt, type(v_play_cnt))
  328. # 抓取时间
  329. v_upload_time = Feishu.get_range_value(
  330. "xiaoniangao", "ba0da4", "H" + str(i) + ":" + "H" + str(i))[0]
  331. Common.logger().info("视频详情,video_send_time:{},{}", v_upload_time, type(v_upload_time))
  332. # 抓取时间:日期
  333. upload_data = v_upload_time.split(" ")[0]
  334. # 抓取时间:小时
  335. upload_hour = v_upload_time.split(" ")[-1].split(":")[0]
  336. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  337. headers = {
  338. "x-b3-traceid": "bd267349bf41b",
  339. "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
  340. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  341. "content-type": "application/json",
  342. "Accept-Encoding": "gzip,compress,br,deflate",
  343. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  344. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  345. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  346. "Referer": "https://servicewechat.com/wxd7911e4c177690e4/617/page-frame.html"
  347. }
  348. data = {
  349. "play_src": "1",
  350. "profile_id": int(p_id),
  351. "profile_mid": int(p_mid),
  352. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  353. "!400x400r/crop/400x400/interlace/1/format/jpg",
  354. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  355. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  356. "share_width": 625,
  357. "share_height": 500,
  358. "no_comments": True,
  359. "no_follow": True,
  360. "vid": v_id,
  361. "hot_l1_comment": True,
  362. "token": "90747742180aeb22c0fe3a3c6a38f3d9",
  363. "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
  364. "proj": "ma",
  365. "wx_ver": "8.0.20",
  366. "code_ver": "3.62.0",
  367. "log_common_params": {
  368. "e": [{
  369. "data": {
  370. "page": "dynamicSharePage"
  371. }
  372. }],
  373. "ext": {
  374. "brand": "iPhone",
  375. "device": "iPhone 11",
  376. "os": "iOS 14.7.1",
  377. "weixinver": "8.0.20",
  378. "srcver": "2.24.3",
  379. "net": "wifi",
  380. "scene": "1089"
  381. },
  382. "pj": "1",
  383. "pf": "2",
  384. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  385. }
  386. }
  387. try:
  388. urllib3.disable_warnings()
  389. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  390. hour_play_cnt = r.json()["data"]["play_pv"]
  391. Common.logger().info("视频详情,当前播放量:{}", hour_play_cnt)
  392. # 固定时间获取符合规则的视频,写入云文档:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=ba0da4
  393. update_hour = datetime.datetime.now()
  394. if upload_data == cls.today and update_hour.hour == 10 and int(upload_hour) <= 10:
  395. Common.logger().info("满足条件: 抓取日期为今天 and 当前时间:10点 and 抓取时间<=10点")
  396. # 当天 10:00 视频播放量
  397. ten_hour_play_cnt = hour_play_cnt
  398. Common.logger().info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  399. # 10:00 的上升榜写入数据
  400. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  401. time.sleep(1)
  402. Feishu.update_values(
  403. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i), [[values]])
  404. Common.logger().info("10:00数据更新成功:{}", values)
  405. elif upload_data == cls.today and update_hour.hour == 15 and int(upload_hour) <= 10:
  406. Common.logger().info("满足条件: 抓取日期为今天 and 当前时间:15点 and 抓取时间<=10点")
  407. # 当天 15:00 视频播放量
  408. fifteen_hour_play_cnt = hour_play_cnt
  409. Common.logger().info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  410. # 当天 10:00 上升的数据
  411. if Feishu.get_range_value(
  412. "xiaoniangao", "ba0da4", "J"+str(i) + ":" + "J"+str(i))[0] is None:
  413. ten_up_cnt = 0
  414. else:
  415. ten_up_cnt = Feishu.get_range_value(
  416. "xiaoniangao", "ba0da4", "J"+str(i) + ":" + "J"+str(i))[0]
  417. # 15:00 的上升榜写入数据
  418. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  419. time.sleep(1)
  420. Feishu.update_values(
  421. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i), [[values]])
  422. Common.logger().info("15:00数据更新成功:{}", values)
  423. elif upload_data == cls.today and update_hour.hour == 15 and 10 < int(upload_hour) <= 15:
  424. Common.logger().info("满足条件: 抓取日期为今天 and 当前时间:15点 and 10<抓取时间<=15点")
  425. # 当天 15:00 视频播放量
  426. fifteen_hour_play_cnt = hour_play_cnt
  427. Common.logger().info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  428. # 15:00 的上升榜写入数据
  429. values = int(fifteen_hour_play_cnt) - int(v_play_cnt)
  430. time.sleep(1)
  431. Feishu.update_values(
  432. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i), [[values]])
  433. Common.logger().info("15:00数据更新成功:{}", values)
  434. elif upload_data == cls.today and update_hour.hour == 20 and int(upload_hour) <= 10:
  435. Common.logger().info("满足条件: 抓取日期为今天 and 当前时间:20点 and 抓取时间<=10点")
  436. # 当天 20:00 视频播放量
  437. twenty_hour_play_cnt = hour_play_cnt
  438. Common.logger().info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  439. # 当天 10:00 上升的数据
  440. if Feishu.get_range_value(
  441. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i))[0] is None:
  442. ten_up_cnt = 0
  443. else:
  444. ten_up_cnt = Feishu.get_range_value(
  445. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i))[0]
  446. # 当天 15:00 上升的数据
  447. if Feishu.get_range_value(
  448. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i))[0] is None:
  449. fifteen_up_cnt = 0
  450. else:
  451. fifteen_up_cnt = Feishu.get_range_value(
  452. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i))[0]
  453. # 20:00 的上升榜写入数据
  454. values = int(twenty_hour_play_cnt) - (
  455. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  456. time.sleep(1)
  457. Feishu.update_values(
  458. "xiaoniangao", "ba0da4", "L" + str(i) + ":" + "L" + str(i), [[values]])
  459. Common.logger().info("20:00数据更新成功:{}", values)
  460. elif upload_data == cls.today and update_hour.hour == 20 and 10 < int(upload_hour) <= 15:
  461. Common.logger().info("满足条件: 抓取日期为今天 and 当前时间:20点 and 10<抓取时间<=15点")
  462. # 当天 20:00 视频播放量
  463. twenty_hour_play_cnt = hour_play_cnt
  464. Common.logger().info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  465. # 当天 15:00 上升的数据
  466. if Feishu.get_range_value(
  467. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i))[0] is None:
  468. fifteen_up_cnt = 0
  469. else:
  470. fifteen_up_cnt = Feishu.get_range_value(
  471. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i))[0]
  472. # 20:00 的上升榜写入数据
  473. values = int(twenty_hour_play_cnt) - (int(v_play_cnt) + int(fifteen_up_cnt))
  474. time.sleep(1)
  475. Feishu.update_values(
  476. "xiaoniangao", "ba0da4", "L" + str(i) + ":" + "L" + str(i), [[values]])
  477. Common.logger().info("20:00数据更新成功:{}", values)
  478. elif upload_data == cls.today and update_hour.hour == 20 and 15 < int(upload_hour) <= 20:
  479. Common.logger().info("满足条件: 抓取日期为今天 and 当前时间:20点 and 15<抓取时间<=20点")
  480. # 当天 20:00 视频播放量
  481. twenty_hour_play_cnt = hour_play_cnt
  482. Common.logger().info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  483. # 20:00 的上升榜写入数据
  484. values = int(twenty_hour_play_cnt) - int(v_play_cnt)
  485. time.sleep(1)
  486. Feishu.update_values(
  487. "xiaoniangao", "ba0da4", "L" + str(i) + ":" + "L" + str(i), [[values]])
  488. Common.logger().info("20:00数据更新成功:{}", values)
  489. elif (upload_data == cls.yesterday or upload_data == cls.before_yesterday)\
  490. and update_hour.hour == 10:
  491. Common.logger().info("满足条件: 抓取时间小于今天 and 当前时间:10点")
  492. # 当天 10:00 视频播放量
  493. ten_hour_play_cnt = hour_play_cnt
  494. Common.logger().info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  495. # 10:00 的上升榜写入数据
  496. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  497. time.sleep(1)
  498. Feishu.update_values(
  499. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i), [[values]])
  500. Common.logger().info("10:00数据更新成功:{}", values)
  501. elif (upload_data == cls.yesterday or upload_data == cls.before_yesterday)\
  502. and update_hour.hour == 15:
  503. Common.logger().info("满足条件: 抓取时间小于今天 and 当前时间:15点")
  504. # 当天 15:00 视频播放量
  505. fifteen_hour_play_cnt = hour_play_cnt
  506. Common.logger().info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  507. # 当天 10:00 上升的数据
  508. if Feishu.get_range_value(
  509. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i))[0] is None:
  510. ten_up_cnt = 0
  511. else:
  512. ten_up_cnt = Feishu.get_range_value(
  513. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i))[0]
  514. # 15:00 的上升榜写入数据
  515. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  516. time.sleep(1)
  517. Feishu.update_values(
  518. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i), [[values]])
  519. Common.logger().info("15:00数据更新成功:{}", values)
  520. elif (upload_data == cls.yesterday or upload_data == cls.before_yesterday)\
  521. and update_hour.hour == 20:
  522. Common.logger().info("满足条件: 抓取时间小于今天 and 当前时间:20点")
  523. # 当天 20:00 视频播放量
  524. twenty_hour_play_cnt = hour_play_cnt
  525. Common.logger().info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  526. # 当天 10:00 上升的数据
  527. if Feishu.get_range_value(
  528. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i))[0] is None:
  529. ten_up_cnt = 0
  530. else:
  531. ten_up_cnt = Feishu.get_range_value(
  532. "xiaoniangao", "ba0da4", "J" + str(i) + ":" + "J" + str(i))[0]
  533. # 当天 15:00 上升的数据
  534. if Feishu.get_range_value(
  535. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i))[0] is None:
  536. fifteen_up_cnt = 0
  537. else:
  538. fifteen_up_cnt = Feishu.get_range_value(
  539. "xiaoniangao", "ba0da4", "K" + str(i) + ":" + "K" + str(i))[0]
  540. # 20:00 的上升榜写入数据
  541. values = int(twenty_hour_play_cnt) - (
  542. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  543. time.sleep(1)
  544. Feishu.update_values(
  545. "xiaoniangao", "ba0da4", "L" + str(i) + ":" + "L" + str(i), [[values]])
  546. Common.logger().info("20:00数据更新成功:{}", values)
  547. except Exception as e:
  548. Common.logger().error("视频详情:{},异常:{}", v_title, e)
  549. except Exception as e:
  550. Common.logger().error("获取小时榜数据异常:{}", e)
  551. if __name__ == "__main__":
  552. hour_list = HourList()
  553. hour_list.get_hour_list_feeds()
  554. # hour_list.del_null_rows("xiaoniangao", "ba0da4", 3)
  555. hour_list.update_hour_list_data()