hour_list.py 34 KB

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