hour_list.py 35 KB

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