hour_list.py 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2022/5/16
  4. import datetime
  5. import os
  6. import sys
  7. import time
  8. import requests
  9. import urllib3
  10. sys.path.append(os.getcwd())
  11. from main.common import Common
  12. from main.feishu_lib import Feishu
  13. from main.publish import Publish
  14. proxies = {"http": None, "https": None}
  15. class HourList:
  16. # 配置微信
  17. time.sleep(1)
  18. wechat_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "dzcWHw")
  19. hour_x_b3_traceid = wechat_sheet[2][1]
  20. hour_x_token_id = wechat_sheet[3][1]
  21. hour_referer = wechat_sheet[4][1]
  22. hour_uid = wechat_sheet[5][1]
  23. hour_token = wechat_sheet[6][1]
  24. # 小时级数据表
  25. hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  26. # 过滤敏感词
  27. @classmethod
  28. def sensitive_words(cls, log_type):
  29. # 敏感词库列表
  30. word_list = []
  31. # 从云文档读取所有敏感词,添加到词库列表
  32. time.sleep(1)
  33. lists = Feishu.get_values_batch(log_type, "xiaoniangao", "DRAnZh")
  34. for i in lists:
  35. for j in i:
  36. # 过滤空的单元格内容
  37. if j is None:
  38. pass
  39. else:
  40. word_list.append(j)
  41. return word_list
  42. # 视频ID过滤字母
  43. @classmethod
  44. def sensitive_videoid_words(cls):
  45. # 字母列表
  46. words_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  47. "t", "u", "v", "w", "x", "y", "z",
  48. "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
  49. "T", "U", "V", "W", "X", "Y", "Z"]
  50. return words_list
  51. # 基础门槛规则
  52. @staticmethod
  53. def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt, d_send_time):
  54. """
  55. 下载视频的基本规则
  56. :param d_duration: 时长
  57. :param d_width: 宽
  58. :param d_height: 高
  59. :param d_play_cnt: 播放量
  60. :param d_like_cnt: 点赞量
  61. :param d_share_cnt: 分享量
  62. :param d_send_time: 发布时间
  63. :return: 满足规则,返回 True;反之,返回 False
  64. """
  65. # 视频时长
  66. if int(float(d_duration)) >= 40:
  67. # 宽或高
  68. if int(d_width) >= 0 or int(d_height) >= 0:
  69. # 播放量
  70. if int(d_play_cnt) >= 4000:
  71. # 点赞量
  72. if int(d_like_cnt) >= 0:
  73. # 分享量
  74. if int(d_share_cnt) >= 0:
  75. # 发布时间 <= 10 天
  76. if int(time.time()) - int(d_send_time)/1000 <= 864000:
  77. return True
  78. else:
  79. return False
  80. else:
  81. return False
  82. else:
  83. return False
  84. else:
  85. return False
  86. return False
  87. return False
  88. # 检查是否有今日的上升榜日期
  89. @classmethod
  90. def check_hour_list_data(cls, log_type, date):
  91. # 判断J1单元格的日期是否为今天
  92. time.sleep(1)
  93. if Feishu.get_range_value(log_type, "xiaoniangao", "ba0da4", "L1:L1")[0] != date:
  94. # 插入3列 L1:N1,并写入日期和时间数据
  95. values = [[date], ["10:00", "15:00", "20:00"]]
  96. time.sleep(1)
  97. Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "COLUMNS", 11, 14)
  98. time.sleep(1)
  99. Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "L1:N2", values)
  100. time.sleep(1)
  101. Feishu.merge_cells(log_type, "xiaoniangao", "ba0da4", "L1:N1")
  102. Common.logger(log_type).info("插入今天日期成功")
  103. else:
  104. Common.logger(log_type).info("今日上升榜日期已存在")
  105. # 获取列表
  106. @classmethod
  107. def get_hour_list_feeds(cls, log_type):
  108. """
  109. 1.从列表获取视频,7 天内,播放量>=5000
  110. 2.时长 1-10min
  111. 3.每天10:00、15:00、20:00 把符合规则的视频,写入云文档
  112. https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  113. """
  114. url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
  115. headers = {
  116. "x-b3-traceid": cls.hour_x_b3_traceid,
  117. "X-Token-Id": cls.hour_x_token_id,
  118. "uid": cls.hour_uid,
  119. "content-type": "application/json",
  120. "Accept-Encoding": "gzip,compress,br,deflate",
  121. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  122. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  123. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  124. "Referer": cls.hour_referer
  125. }
  126. data = {
  127. "log_params": {
  128. "page": "discover_rec",
  129. "common": {
  130. "brand": "iPhone",
  131. "device": "iPhone 11",
  132. "os": "iOS 14.7.1",
  133. "weixinver": "8.0.20",
  134. "srcver": "2.24.2",
  135. "net": "wifi",
  136. "scene": 1089
  137. }
  138. },
  139. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
  140. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!80x80r/crop/80x80/interlace/1/format/jpg",
  141. "share_width": 625,
  142. "share_height": 500,
  143. "ext": {
  144. "fmid": 0,
  145. "items": {}
  146. },
  147. "app": "xng",
  148. "rec_scene": "discover_rec",
  149. "log_common_params": {
  150. "e": [{
  151. "data": {
  152. "page": "discoverIndexPage",
  153. "topic": "recommend"
  154. },
  155. "ab": {}
  156. }],
  157. "ext": {
  158. "brand": "iPhone",
  159. "device": "iPhone 11",
  160. "os": "iOS 14.7.1",
  161. "weixinver": "8.0.20",
  162. "srcver": "2.24.3",
  163. "net": "wifi",
  164. "scene": "1089"
  165. },
  166. "pj": "1",
  167. "pf": "2",
  168. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  169. },
  170. "refresh": False,
  171. "token": cls.hour_token,
  172. "uid": cls.hour_uid,
  173. "proj": "ma",
  174. "wx_ver": "8.0.20",
  175. "code_ver": "3.62.0"
  176. }
  177. try:
  178. urllib3.disable_warnings()
  179. r = requests.post(url=url, headers=headers, json=data, proxies=proxies, verify=False)
  180. if "data" not in r.json():
  181. Common.logger(log_type).warning("获取视频feeds错误:{}", r.text)
  182. elif "list" not in r.json()["data"]:
  183. Common.logger(log_type).warning("获取视频feeds无数据,休眠10s:{}", r.json()["data"])
  184. else:
  185. # 视频列表数据
  186. feeds = r.json()["data"]["list"]
  187. for i in range(len(feeds)):
  188. # 标题
  189. if "title" in feeds[i]:
  190. video_title = feeds[i]["title"].strip().replace("\n", "") \
  191. .replace("/", "").replace("\r", "").replace("#", "") \
  192. .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
  193. .replace(":", "").replace("*", "").replace("?", "") \
  194. .replace("?", "").replace('"', "").replace("<", "") \
  195. .replace(">", "").replace("|", "").replace(" ", "")
  196. else:
  197. video_title = 0
  198. # 视频 ID
  199. if "vid" in feeds[i]:
  200. video_id = feeds[i]["vid"]
  201. else:
  202. video_id = 0
  203. # 播放量
  204. if "play_pv" in feeds[i]:
  205. video_play_cnt = feeds[i]["play_pv"]
  206. else:
  207. video_play_cnt = 0
  208. # 点赞量
  209. if "favor" in feeds[i]:
  210. video_like_cnt = feeds[i]["favor"]["total"]
  211. else:
  212. video_like_cnt = 0
  213. # 分享量
  214. if "share" in feeds[i]:
  215. video_share_cnt = feeds[i]["share"]
  216. else:
  217. video_share_cnt = 0
  218. # # 评论量
  219. # if "comment_count" in feeds[i]:
  220. # video_comment_cnt = feeds[i]["comment_count"]
  221. # else:
  222. # video_comment_cnt = 0
  223. # 时长
  224. if "du" in feeds[i]:
  225. video_duration = int(feeds[i]["du"] / 1000)
  226. else:
  227. video_duration = 0
  228. # 宽和高
  229. if "w" or "h" in feeds[i]:
  230. video_width = feeds[i]["w"]
  231. video_height = feeds[i]["h"]
  232. else:
  233. video_width = 0
  234. video_height = 0
  235. # 发布时间
  236. if "t" in feeds[i]:
  237. video_send_time = feeds[i]["t"]
  238. else:
  239. video_send_time = 0
  240. # 用户名 / 头像
  241. if "user" in feeds[i]:
  242. user_name = feeds[i]["user"]["nick"].strip().replace("\n", "") \
  243. .replace("/", "").replace("快手", "").replace(" ", "") \
  244. .replace(" ", "").replace("&NBSP", "").replace("\r", "")
  245. head_url = feeds[i]["user"]["hurl"]
  246. else:
  247. user_name = 0
  248. head_url = 0
  249. # 用户 ID
  250. profile_id = feeds[i]["id"]
  251. # 用户 mid
  252. profile_mid = feeds[i]["user"]["mid"]
  253. # 视频封面
  254. if "url" in feeds[i]:
  255. cover_url = feeds[i]["url"]
  256. else:
  257. cover_url = 0
  258. # 视频播放地址
  259. if "v_url" in feeds[i]:
  260. video_url = feeds[i]["v_url"]
  261. else:
  262. video_url = 0
  263. Common.logger(log_type).info("标题:{}", video_title)
  264. Common.logger(log_type).info("视频ID:{}", video_id)
  265. Common.logger(log_type).info("播放量:{}", video_play_cnt)
  266. # Common.logger(log_type).info("点赞量:{}", video_like_cnt)
  267. # Common.logger(log_type).info("分享量:{}", video_share_cnt)
  268. # Common.logger(log_type).info("评论数:{}", video_comment_cnt)
  269. Common.logger(log_type).info("时长:{}秒", video_duration)
  270. # Common.logger(log_type).info("宽高:{}*{}", video_width, video_height)
  271. Common.logger(log_type).info(
  272. "视频发布时间:{}", time.strftime(
  273. "%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
  274. Common.logger(log_type).info("用户名:{}", user_name)
  275. # Common.logger(log_type).info("用户头像:{}", head_url)
  276. # Common.logger(log_type).info("封面:{}", cover_url)
  277. Common.logger(log_type).info("播放地址:{}", video_url)
  278. # 过滤无效视频
  279. if video_title == 0 or video_id == 0 or video_duration == 0 \
  280. or video_send_time == 0 or user_name == 0 or head_url == 0 \
  281. or cover_url == 0 or video_url == 0:
  282. Common.logger(log_type).warning("无效视频")
  283. elif cls.download_rule(video_duration, video_width, video_height, video_play_cnt,
  284. video_like_cnt, video_share_cnt, video_send_time) is False:
  285. Common.logger(log_type).info("不满足基础门槛规则")
  286. # 过滤敏感词
  287. elif any(word if word in video_title else False for word in cls.sensitive_words(log_type)) is True:
  288. Common.logger(log_type).info("视频已中敏感词:{}".format(video_title))
  289. time.sleep(1)
  290. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  291. elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
  292. Common.logger(log_type).info("该视频已下载:{}", video_title)
  293. time.sleep(1)
  294. # 从云文档去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  295. elif video_id in [j for i in Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4") for j in i]:
  296. Common.logger(log_type).info("该视频已保存过:{}", video_title)
  297. time.sleep(1)
  298. else:
  299. Common.logger(log_type).info("该视频未下载,添加至feeds中:{}".format(video_title))
  300. # feeds工作表,插入空行
  301. time.sleep(1)
  302. Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "ROWS", 2, 3)
  303. # 获取当前时间
  304. get_feeds_time = int(time.time())
  305. # 看一看云文档,工作表中写入数据
  306. values = [[profile_id,
  307. profile_mid,
  308. video_id,
  309. video_title,
  310. user_name,
  311. video_duration,
  312. cover_url,
  313. video_url,
  314. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
  315. str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(get_feeds_time))),
  316. video_play_cnt]]
  317. # 等待 1s,防止操作云文档太频繁,导致报错
  318. time.sleep(1)
  319. Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "A3:K3", values)
  320. except Exception as e:
  321. Common.logger(log_type).error("获取小时榜视频列表异常:{}", e)
  322. # 更新小时榜数据
  323. @classmethod
  324. def update_hour_list_data(cls, log_type, today, yesterday, before_yesterday):
  325. """
  326. 更新小时榜数据
  327. """
  328. try:
  329. update_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  330. if len(update_hour_sheet) == 2:
  331. Common.logger(log_type).info("当前工作表无数据")
  332. else:
  333. for i in range(2, len(update_hour_sheet)+1):
  334. Common.logger(log_type).info("更新第:{}行视频信息", i+1)
  335. # 略过空行
  336. if update_hour_sheet[i][0] is None \
  337. or update_hour_sheet[i][1] is None or update_hour_sheet[i][2] is None:
  338. Common.logger(log_type).info("空行,略过")
  339. else:
  340. # 视频标题
  341. v_title = update_hour_sheet[i][3]
  342. Common.logger(log_type).info("video_title:{}", v_title)
  343. # 视频 ID
  344. v_id = update_hour_sheet[i][2]
  345. Common.logger(log_type).info("video_id:{}", v_id)
  346. # profile_id,用户 ID
  347. p_id = update_hour_sheet[i][0]
  348. Common.logger(log_type).info("profile_id:{}", p_id)
  349. # profile_mid
  350. p_mid = update_hour_sheet[i][1]
  351. Common.logger(log_type).info("profile_mid:{}", p_mid)
  352. # 抓取时的播放量
  353. v_play_cnt = update_hour_sheet[i][10]
  354. Common.logger(log_type).info("video_play_cnt:{}", v_play_cnt)
  355. # 抓取时间
  356. v_upload_time = update_hour_sheet[i][9]
  357. Common.logger(log_type).info("video_send_time:{}", v_upload_time)
  358. # 抓取时间的时间戳格式(秒为单位)
  359. v_time = int(time.mktime(time.strptime(v_upload_time, "%Y-%m-%d %H:%M:%S")))
  360. # 抓取时间:日期
  361. upload_data = v_upload_time.split(" ")[0]
  362. # 抓取时间:小时
  363. upload_hour = v_upload_time.split(" ")[-1].split(":")[0]
  364. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  365. headers = {
  366. "x-b3-traceid": cls.hour_x_b3_traceid,
  367. "X-Token-Id": cls.hour_x_token_id,
  368. "uid": cls.hour_uid,
  369. "content-type": "application/json",
  370. "Accept-Encoding": "gzip,compress,br,deflate",
  371. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  372. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  373. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  374. "Referer": cls.hour_referer
  375. }
  376. data = {
  377. "play_src": "1",
  378. "profile_id": int(p_id),
  379. "profile_mid": int(p_mid),
  380. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  381. "!400x400r/crop/400x400/interlace/1/format/jpg",
  382. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  383. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  384. "share_width": 625,
  385. "share_height": 500,
  386. "no_comments": True,
  387. "no_follow": True,
  388. "vid": v_id,
  389. "hot_l1_comment": True,
  390. "token": cls.hour_token,
  391. "uid": cls.hour_uid,
  392. "proj": "ma",
  393. "wx_ver": "8.0.20",
  394. "code_ver": "3.62.0",
  395. "log_common_params": {
  396. "e": [{
  397. "data": {
  398. "page": "dynamicSharePage"
  399. }
  400. }],
  401. "ext": {
  402. "brand": "iPhone",
  403. "device": "iPhone 11",
  404. "os": "iOS 14.7.1",
  405. "weixinver": "8.0.20",
  406. "srcver": "2.24.3",
  407. "net": "wifi",
  408. "scene": "1089"
  409. },
  410. "pj": "1",
  411. "pf": "2",
  412. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  413. }
  414. }
  415. try:
  416. urllib3.disable_warnings()
  417. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  418. hour_play_cnt = r.json()["data"]["play_pv"]
  419. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  420. # 固定时间获取符合规则的视频,写入云文档:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=ba0da4
  421. update_hour = datetime.datetime.now()
  422. if int(time.time()) - v_time >= 172800:
  423. Common.logger(log_type).info("抓取时间超过 2 天")
  424. return
  425. elif upload_data == today and update_hour.hour == 10 and int(upload_hour) <= 10:
  426. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:10点 and 抓取时间<=10点")
  427. # 当天 10:00 视频播放量
  428. ten_hour_play_cnt = hour_play_cnt
  429. Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
  430. # 10:00 的上升榜写入数据
  431. values = int(ten_hour_play_cnt) - int(v_play_cnt)
  432. time.sleep(1)
  433. Feishu.update_values(
  434. log_type, "xiaoniangao", "ba0da4",
  435. "L" + str(i+1) + ":" + "L" + str(i+1), [[values]])
  436. Common.logger(log_type).info("10:00数据更新成功:{}", values)
  437. elif upload_data == today and update_hour.hour == 15 and int(upload_hour) <= 10:
  438. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 抓取时间<=10点")
  439. # 当天 15:00 视频播放量
  440. fifteen_hour_play_cnt = hour_play_cnt
  441. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  442. # 当天 10:00 上升的数据
  443. if update_hour_sheet[i][11] is None:
  444. ten_up_cnt = 0
  445. else:
  446. ten_up_cnt = update_hour_sheet[i][11]
  447. # 15:00 的上升榜写入数据
  448. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  449. time.sleep(1)
  450. Feishu.update_values(
  451. log_type, "xiaoniangao", "ba0da4",
  452. "M" + str(i+1) + ":" + "M" + str(i+1), [[values]])
  453. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  454. elif upload_data == today and update_hour.hour == 15 and 10 < int(upload_hour) <= 15:
  455. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 10<抓取时间<=15点")
  456. # 当天 15:00 视频播放量
  457. fifteen_hour_play_cnt = hour_play_cnt
  458. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  459. # 15:00 的上升榜写入数据
  460. values = int(fifteen_hour_play_cnt) - int(v_play_cnt)
  461. time.sleep(1)
  462. Feishu.update_values(
  463. log_type, "xiaoniangao", "ba0da4",
  464. "M" + str(i+1) + ":" + "M" + str(i+1), [[values]])
  465. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  466. elif upload_data == today and update_hour.hour == 20 and int(upload_hour) <= 10:
  467. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 抓取时间<=10点")
  468. # 当天 20:00 视频播放量
  469. twenty_hour_play_cnt = hour_play_cnt
  470. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  471. # 当天 10:00 上升的数据
  472. if update_hour_sheet[i][11] is None:
  473. ten_up_cnt = 0
  474. else:
  475. ten_up_cnt = update_hour_sheet[i][11]
  476. # 当天 15:00 上升的数据
  477. if update_hour_sheet[i][12] is None:
  478. fifteen_up_cnt = 0
  479. else:
  480. fifteen_up_cnt = update_hour_sheet[i][12]
  481. # 20:00 的上升榜写入数据
  482. values = int(twenty_hour_play_cnt) - (
  483. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  484. time.sleep(1)
  485. Feishu.update_values(
  486. log_type, "xiaoniangao", "ba0da4",
  487. "N" + str(i+1) + ":" + "N" + str(i+1), [[values]])
  488. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  489. elif upload_data == today and update_hour.hour == 20 and 10 < int(upload_hour) <= 15:
  490. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 10<抓取时间<=15点")
  491. # 当天 20:00 视频播放量
  492. twenty_hour_play_cnt = hour_play_cnt
  493. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  494. # 当天 15:00 上升的数据
  495. if update_hour_sheet[i][12] is None:
  496. fifteen_up_cnt = 0
  497. else:
  498. fifteen_up_cnt = update_hour_sheet[i][12]
  499. # 20:00 的上升榜写入数据
  500. values = int(twenty_hour_play_cnt) - (int(v_play_cnt) + int(fifteen_up_cnt))
  501. time.sleep(1)
  502. Feishu.update_values(
  503. log_type, "xiaoniangao", "ba0da4",
  504. "N" + str(i+1) + ":" + "N" + str(i+1), [[values]])
  505. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  506. elif upload_data == today and update_hour.hour == 20 and 15 < int(upload_hour) <= 20:
  507. Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 15<抓取时间<=20点")
  508. # 当天 20:00 视频播放量
  509. twenty_hour_play_cnt = hour_play_cnt
  510. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  511. # 20:00 的上升榜写入数据
  512. values = int(twenty_hour_play_cnt) - int(v_play_cnt)
  513. time.sleep(1)
  514. Feishu.update_values(
  515. log_type, "xiaoniangao", "ba0da4",
  516. "N" + str(i+1) + ":" + "N" + str(i+1), [[values]])
  517. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  518. elif (upload_data == yesterday or upload_data == before_yesterday)\
  519. and update_hour.hour == 10:
  520. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:10点")
  521. # 当天 10:00 视频播放量
  522. ten_hour_play_cnt = hour_play_cnt
  523. Common.logger(log_type).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. log_type, "xiaoniangao", "ba0da4",
  529. "L" + str(i+1) + ":" + "L" + str(i+1), [[values]])
  530. Common.logger(log_type).info("10:00数据更新成功:{}", values)
  531. elif (upload_data == yesterday or upload_data == before_yesterday)\
  532. and update_hour.hour == 15:
  533. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:15点")
  534. # 当天 15:00 视频播放量
  535. fifteen_hour_play_cnt = hour_play_cnt
  536. Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
  537. # 当天 10:00 上升的数据
  538. if update_hour_sheet[i][11] is None:
  539. ten_up_cnt = 0
  540. else:
  541. ten_up_cnt = update_hour_sheet[i][11]
  542. # 15:00 的上升榜写入数据
  543. values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
  544. time.sleep(1)
  545. Feishu.update_values(
  546. log_type, "xiaoniangao", "ba0da4",
  547. "M" + str(i+1) + ":" + "M" + str(i+1), [[values]])
  548. Common.logger(log_type).info("15:00数据更新成功:{}", values)
  549. elif (upload_data == yesterday or upload_data == before_yesterday)\
  550. and update_hour.hour == 20:
  551. Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:20点")
  552. # 当天 20:00 视频播放量
  553. twenty_hour_play_cnt = hour_play_cnt
  554. Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
  555. # 当天 10:00 上升的数据
  556. if update_hour_sheet[i][11] is None:
  557. ten_up_cnt = 0
  558. else:
  559. ten_up_cnt = update_hour_sheet[i][11]
  560. # 当天 15:00 上升的数据
  561. if update_hour_sheet[i][12] is None:
  562. fifteen_up_cnt = 0
  563. else:
  564. fifteen_up_cnt = update_hour_sheet[i][12]
  565. # 20:00 的上升榜写入数据
  566. values = int(twenty_hour_play_cnt) - (
  567. int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
  568. time.sleep(1)
  569. Feishu.update_values(
  570. log_type, "xiaoniangao", "ba0da4",
  571. "N" + str(i+1) + ":" + "N" + str(i+1), [[values]])
  572. Common.logger(log_type).info("20:00数据更新成功:{}", values)
  573. except Exception as e:
  574. Common.logger(log_type).error("视频详情:{},异常:{}", v_title, e)
  575. except Exception as e:
  576. Common.logger(log_type).error("获取小时榜数据异常:{}", e)
  577. # 下载/上传
  578. @classmethod
  579. def download_and_publish(cls, log_type):
  580. """
  581. 1.从云文档中去重: https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  582. 2.从云文档中下载符合规则的视频:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
  583. 2.1 当日 10:00 or 15:00 or 20:00 视频播放量上升 > 5000
  584. 2.2 当日 10:00 and 15:00 视频播放量上升 > 2000
  585. 2.3 当日 15:00 and 20:00 视频播放量上升 > 2000
  586. 2.4 昨日 20:00 and 今日 10:00 视频播放量上升 > 2000
  587. 3.上传
  588. """
  589. try:
  590. time.sleep(1)
  591. download_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
  592. if len(download_hour_sheet) == 2:
  593. Common.logger(log_type).info("当前工作表无数据")
  594. else:
  595. for i in range(2, len(download_hour_sheet)+1):
  596. Common.logger(log_type).info("分析第:{}行视频信息是否符合下载规则", i+1)
  597. # 略过空行
  598. if download_hour_sheet[i][0] is None \
  599. or download_hour_sheet[i][1] is None or download_hour_sheet[i][2] is None:
  600. Common.logger(log_type).info("空行,略过")
  601. else:
  602. # 今日 10:00 数据上升量
  603. if download_hour_sheet[i][11] is None:
  604. ten_cnt = 0
  605. else:
  606. ten_cnt = download_hour_sheet[i][11]
  607. # 今日 15:00 数据上升量
  608. if download_hour_sheet[i][12] is None:
  609. fifteen_cnt = 0
  610. else:
  611. fifteen_cnt = download_hour_sheet[i][12]
  612. # 今日 20:00 数据上升量
  613. if download_hour_sheet[i][13] is None:
  614. twenty_cnt = 0
  615. else:
  616. twenty_cnt = download_hour_sheet[i][13]
  617. # 昨日 20:00 数据上升量
  618. if download_hour_sheet[i][16] is None:
  619. yesterday_twenty_cnt = 0
  620. else:
  621. yesterday_twenty_cnt = download_hour_sheet[i][16]
  622. # 视频标题
  623. v_title = download_hour_sheet[i][3]
  624. Common.logger(log_type).info("video_title:{}", v_title)
  625. # 视频 ID
  626. v_id = download_hour_sheet[i][2]
  627. Common.logger(log_type).info("video_id:{}", v_id)
  628. # profile_id,用户 ID
  629. p_id = download_hour_sheet[i][0]
  630. # 视频时长
  631. v_duration = download_hour_sheet[i][5]
  632. # profile_mid
  633. p_mid = download_hour_sheet[i][1]
  634. Common.logger(log_type).info("10:00 / 15:00 / 20:00 上升量: {} / {} / {}",
  635. ten_cnt, fifteen_cnt, twenty_cnt)
  636. # 抓取时间
  637. v_upload_time = download_hour_sheet[i][9]
  638. v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y-%m-%d %H:%M:%S")))
  639. # 播放量
  640. v_play_cnt = download_hour_sheet[i][10]
  641. # # 判断视频 ID 长度,不大于 13 位
  642. # if len(str(v_id)) > 13:
  643. # Common.logger(log_type).info("视频ID长度大于13位:{}", v_id)
  644. #
  645. # el
  646. if int(time.time()) - int(v_send_time) >= 259200:
  647. Common.logger(log_type).info("抓取时间超过 3 天")
  648. return
  649. # 判断视频时长:1-10min
  650. elif int(v_duration) < 40:
  651. Common.logger(log_type).info("视频时长小于 40s")
  652. # # 过滤带字母的视频ID
  653. # elif any(word if word in v_id else False for word in cls.sensitive_videoid_words()) is True:
  654. # Common.logger(log_type).info("视频ID带字母:{}".format(v_id))
  655. # 从云文档中去重:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
  656. elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
  657. Common.logger(log_type).info("该视频已下载:{}", v_title)
  658. # 播放量大于 100000,直接下载
  659. elif int(v_play_cnt) >= 100000:
  660. Common.logger(log_type).info("播放量:{} >= 100000,满足下载规则,开始下载视频", v_play_cnt)
  661. try:
  662. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  663. headers = {
  664. "x-b3-traceid": cls.hour_x_b3_traceid,
  665. "X-Token-Id": cls.hour_x_token_id,
  666. "uid": cls.hour_uid,
  667. "content-type": "application/json",
  668. "Accept-Encoding": "gzip,compress,br,deflate",
  669. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  670. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  671. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  672. "Referer": cls.hour_referer
  673. }
  674. data = {
  675. "play_src": "1",
  676. "profile_id": int(p_id),
  677. "profile_mid": int(p_mid),
  678. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  679. "!400x400r/crop/400x400/interlace/1/format/jpg",
  680. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  681. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  682. "share_width": 625,
  683. "share_height": 500,
  684. "no_comments": True,
  685. "no_follow": True,
  686. "vid": v_id,
  687. "hot_l1_comment": True,
  688. "token": cls.hour_token,
  689. "uid": cls.hour_uid,
  690. "proj": "ma",
  691. "wx_ver": "8.0.20",
  692. "code_ver": "3.62.0",
  693. "log_common_params": {
  694. "e": [{
  695. "data": {
  696. "page": "dynamicSharePage"
  697. }
  698. }],
  699. "ext": {
  700. "brand": "iPhone",
  701. "device": "iPhone 11",
  702. "os": "iOS 14.7.1",
  703. "weixinver": "8.0.20",
  704. "srcver": "2.24.3",
  705. "net": "wifi",
  706. "scene": "1089"
  707. },
  708. "pj": "1",
  709. "pf": "2",
  710. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  711. }
  712. }
  713. urllib3.disable_warnings()
  714. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  715. hour_play_cnt = r.json()["data"]["play_pv"]
  716. hour_cover_url = r.json()["data"]["url"]
  717. hour_video_url = r.json()["data"]["v_url"]
  718. hour_video_duration = r.json()["data"]["du"]
  719. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  720. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  721. hour_video_share_cnt = r.json()["data"]["share"]
  722. hour_video_width = r.json()["data"]["w"]
  723. hour_video_height = r.json()["data"]["h"]
  724. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  725. hour_video_send_time = r.json()["data"]["t"]
  726. hour_user_name = r.json()["data"]["user"]["nick"]
  727. hour_head_url = r.json()["data"]["user"]["hurl"]
  728. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  729. # 下载封面
  730. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  731. # 下载视频
  732. Common.download_method(log_type, "video", v_title, hour_video_url)
  733. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  734. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  735. f_a.write(str(v_id) + "\n" +
  736. str(v_title) + "\n" +
  737. str(int(int(hour_video_duration) / 1000)) + "\n" +
  738. str(hour_play_cnt) + "\n" +
  739. str(hour_video_comment_cnt) + "\n" +
  740. str(hour_video_like_cnt) + "\n" +
  741. str(hour_video_share_cnt) + "\n" +
  742. str(hour_video_resolution) + "\n" +
  743. str(hour_video_send_time) + "\n" +
  744. str(hour_user_name) + "\n" +
  745. str(hour_head_url) + "\n" +
  746. str(hour_video_url) + "\n" +
  747. str(hour_cover_url) + "\n" +
  748. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  749. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  750. # 上传视频
  751. Common.logger(log_type).info("开始上传视频")
  752. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  753. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  754. our_video_id) + "/info"
  755. Common.logger(log_type).info("视频上传完成:{}", v_title)
  756. # 上传完成时间
  757. upload_time = int(time.time())
  758. # 保存视频信息到云文档
  759. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  760. # 插入空行
  761. time.sleep(1)
  762. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  763. # 视频信息写入云文档
  764. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(upload_time))),
  765. "小时级上升榜",
  766. v_id,
  767. v_title,
  768. our_video_link,
  769. hour_play_cnt,
  770. hour_video_comment_cnt,
  771. hour_video_like_cnt,
  772. hour_video_share_cnt,
  773. int(hour_video_duration) / 1000,
  774. hour_video_resolution,
  775. time.strftime("%Y-%m-%d %H:%M:%S",
  776. time.localtime(int(hour_video_send_time) / 1000)),
  777. hour_user_name,
  778. p_id,
  779. p_mid,
  780. hour_head_url,
  781. hour_cover_url,
  782. hour_video_url]]
  783. time.sleep(1)
  784. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  785. # 保存视频信息到监控表
  786. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  787. # 插入空行
  788. time.sleep(1)
  789. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  790. # 视频信息写入监控表
  791. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  792. v_id,
  793. v_title,
  794. our_video_link,
  795. p_id,
  796. p_mid,
  797. hour_user_name,
  798. int(hour_video_duration) / 1000,
  799. time.strftime("%Y/%m/%d %H:%M:%S",
  800. time.localtime(int(hour_video_send_time) / 1000)),
  801. hour_play_cnt]]
  802. time.sleep(1)
  803. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  804. except Exception as e:
  805. Common.logger(log_type).error("下载视频异常:{}", e)
  806. # 上升榜判断逻辑,任意时间段上升量>=5000,连续两个时间段上升量>=2000
  807. elif int(ten_cnt) >= 5000 or int(fifteen_cnt) >= 5000 or int(twenty_cnt) >= 5000:
  808. Common.logger(log_type).info("10:00 or 15:00 or 20:00 数据上升量:{} or {} or {} >= 5000",
  809. ten_cnt, fifteen_cnt, twenty_cnt)
  810. Common.logger(log_type).info("满足下载规则,开始下载视频")
  811. try:
  812. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  813. headers = {
  814. "x-b3-traceid": cls.hour_x_b3_traceid,
  815. "X-Token-Id": cls.hour_x_token_id,
  816. "uid": cls.hour_uid,
  817. "content-type": "application/json",
  818. "Accept-Encoding": "gzip,compress,br,deflate",
  819. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  820. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  821. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  822. "Referer": cls.hour_referer
  823. }
  824. data = {
  825. "play_src": "1",
  826. "profile_id": int(p_id),
  827. "profile_mid": int(p_mid),
  828. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  829. "!400x400r/crop/400x400/interlace/1/format/jpg",
  830. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  831. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  832. "share_width": 625,
  833. "share_height": 500,
  834. "no_comments": True,
  835. "no_follow": True,
  836. "vid": v_id,
  837. "hot_l1_comment": True,
  838. "token": cls.hour_token,
  839. "uid": cls.hour_uid,
  840. "proj": "ma",
  841. "wx_ver": "8.0.20",
  842. "code_ver": "3.62.0",
  843. "log_common_params": {
  844. "e": [{
  845. "data": {
  846. "page": "dynamicSharePage"
  847. }
  848. }],
  849. "ext": {
  850. "brand": "iPhone",
  851. "device": "iPhone 11",
  852. "os": "iOS 14.7.1",
  853. "weixinver": "8.0.20",
  854. "srcver": "2.24.3",
  855. "net": "wifi",
  856. "scene": "1089"
  857. },
  858. "pj": "1",
  859. "pf": "2",
  860. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  861. }
  862. }
  863. urllib3.disable_warnings()
  864. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  865. hour_play_cnt = r.json()["data"]["play_pv"]
  866. hour_cover_url = r.json()["data"]["url"]
  867. hour_video_url = r.json()["data"]["v_url"]
  868. hour_video_duration = r.json()["data"]["du"]
  869. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  870. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  871. hour_video_share_cnt = r.json()["data"]["share"]
  872. hour_video_width = r.json()["data"]["w"]
  873. hour_video_height = r.json()["data"]["h"]
  874. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  875. hour_video_send_time = r.json()["data"]["t"]
  876. hour_user_name = r.json()["data"]["user"]["nick"]
  877. hour_head_url = r.json()["data"]["user"]["hurl"]
  878. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  879. # 下载封面
  880. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  881. # 下载视频
  882. Common.download_method(log_type, "video", v_title, hour_video_url)
  883. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  884. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  885. f_a.write(str(v_id) + "\n" +
  886. str(v_title) + "\n" +
  887. str(int(int(hour_video_duration) / 1000)) + "\n" +
  888. str(hour_play_cnt) + "\n" +
  889. str(hour_video_comment_cnt) + "\n" +
  890. str(hour_video_like_cnt) + "\n" +
  891. str(hour_video_share_cnt) + "\n" +
  892. str(hour_video_resolution) + "\n" +
  893. str(hour_video_send_time) + "\n" +
  894. str(hour_user_name) + "\n" +
  895. str(hour_head_url) + "\n" +
  896. str(hour_video_url) + "\n" +
  897. str(hour_cover_url) + "\n" +
  898. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  899. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  900. # 上传视频
  901. Common.logger(log_type).info("开始上传视频")
  902. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  903. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  904. our_video_id) + "/info"
  905. Common.logger(log_type).info("视频上传完成:{}", v_title)
  906. # 上传完成时间
  907. upload_time = int(time.time())
  908. # 保存视频信息到云文档
  909. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  910. # 插入空行
  911. time.sleep(1)
  912. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  913. # 视频信息写入云文档
  914. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(upload_time))),
  915. "小时级上升榜",
  916. v_id,
  917. v_title,
  918. our_video_link,
  919. hour_play_cnt,
  920. hour_video_comment_cnt,
  921. hour_video_like_cnt,
  922. hour_video_share_cnt,
  923. int(hour_video_duration)/1000,
  924. hour_video_resolution,
  925. time.strftime("%Y-%m-%d %H:%M:%S",
  926. time.localtime(int(hour_video_send_time) / 1000)),
  927. hour_user_name,
  928. p_id,
  929. p_mid,
  930. hour_head_url,
  931. hour_cover_url,
  932. hour_video_url]]
  933. time.sleep(1)
  934. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  935. # 保存视频信息到监控表
  936. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  937. # 插入空行
  938. time.sleep(1)
  939. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  940. # 视频信息写入监控表
  941. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  942. v_id,
  943. v_title,
  944. our_video_link,
  945. p_id,
  946. p_mid,
  947. hour_user_name,
  948. int(hour_video_duration)/1000,
  949. time.strftime("%Y/%m/%d %H:%M:%S",
  950. time.localtime(int(hour_video_send_time) / 1000)),
  951. hour_play_cnt]]
  952. time.sleep(1)
  953. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  954. except Exception as e:
  955. Common.logger(log_type).error("下载视频异常:{}", e)
  956. elif int(ten_cnt) >= 2000 and int(fifteen_cnt) >= 2000:
  957. Common.logger(log_type).info(
  958. "10:00 and 15:00 数据上升量:{} and {} >= 2000", ten_cnt, fifteen_cnt)
  959. Common.logger(log_type).info("满足下载规则,开始下载视频")
  960. try:
  961. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  962. headers = {
  963. "x-b3-traceid": cls.hour_x_b3_traceid,
  964. "X-Token-Id": cls.hour_x_token_id,
  965. "uid": cls.hour_uid,
  966. "content-type": "application/json",
  967. "Accept-Encoding": "gzip,compress,br,deflate",
  968. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  969. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  970. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  971. "Referer": cls.hour_referer
  972. }
  973. data = {
  974. "play_src": "1",
  975. "profile_id": int(p_id),
  976. "profile_mid": int(p_mid),
  977. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  978. "!400x400r/crop/400x400/interlace/1/format/jpg",
  979. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  980. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  981. "share_width": 625,
  982. "share_height": 500,
  983. "no_comments": True,
  984. "no_follow": True,
  985. "vid": v_id,
  986. "hot_l1_comment": True,
  987. "token": cls.hour_token,
  988. "uid": cls.hour_uid,
  989. "proj": "ma",
  990. "wx_ver": "8.0.20",
  991. "code_ver": "3.62.0",
  992. "log_common_params": {
  993. "e": [{
  994. "data": {
  995. "page": "dynamicSharePage"
  996. }
  997. }],
  998. "ext": {
  999. "brand": "iPhone",
  1000. "device": "iPhone 11",
  1001. "os": "iOS 14.7.1",
  1002. "weixinver": "8.0.20",
  1003. "srcver": "2.24.3",
  1004. "net": "wifi",
  1005. "scene": "1089"
  1006. },
  1007. "pj": "1",
  1008. "pf": "2",
  1009. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1010. }
  1011. }
  1012. urllib3.disable_warnings()
  1013. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1014. hour_play_cnt = r.json()["data"]["play_pv"]
  1015. hour_cover_url = r.json()["data"]["url"]
  1016. hour_video_url = r.json()["data"]["v_url"]
  1017. hour_video_duration = r.json()["data"]["du"]
  1018. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1019. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1020. hour_video_share_cnt = r.json()["data"]["share"]
  1021. hour_video_width = r.json()["data"]["w"]
  1022. hour_video_height = r.json()["data"]["h"]
  1023. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1024. hour_video_send_time = r.json()["data"]["t"]
  1025. hour_user_name = r.json()["data"]["user"]["nick"]
  1026. hour_head_url = r.json()["data"]["user"]["hurl"]
  1027. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1028. # 下载封面
  1029. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1030. # 下载视频
  1031. Common.download_method(log_type, "video", v_title, hour_video_url)
  1032. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1033. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1034. f_a.write(str(v_id) + "\n" +
  1035. str(v_title) + "\n" +
  1036. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1037. str(hour_play_cnt) + "\n" +
  1038. str(hour_video_comment_cnt) + "\n" +
  1039. str(hour_video_like_cnt) + "\n" +
  1040. str(hour_video_share_cnt) + "\n" +
  1041. str(hour_video_resolution) + "\n" +
  1042. str(hour_video_send_time) + "\n" +
  1043. str(hour_user_name) + "\n" +
  1044. str(hour_head_url) + "\n" +
  1045. str(hour_video_url) + "\n" +
  1046. str(hour_cover_url) + "\n" +
  1047. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1048. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1049. # 上传
  1050. Common.logger(log_type).info("开始上传视频")
  1051. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1052. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1053. our_video_id) + "/info"
  1054. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1055. # 上传完成时间
  1056. upload_time = int(time.time())
  1057. # 保存视频信息到云文档
  1058. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1059. # 插入空行
  1060. time.sleep(1)
  1061. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1062. # 视频信息写入云文档
  1063. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(upload_time))),
  1064. "小时级上升榜",
  1065. v_id,
  1066. v_title,
  1067. our_video_link,
  1068. hour_play_cnt,
  1069. hour_video_comment_cnt,
  1070. hour_video_like_cnt,
  1071. hour_video_share_cnt,
  1072. int(hour_video_duration) / 1000,
  1073. hour_video_resolution,
  1074. time.strftime("%Y-%m-%d %H:%M:%S",
  1075. time.localtime(int(hour_video_send_time) / 1000)),
  1076. hour_user_name,
  1077. p_id,
  1078. p_mid,
  1079. hour_head_url,
  1080. hour_cover_url,
  1081. hour_video_url]]
  1082. time.sleep(1)
  1083. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1084. # 保存视频信息到监控表
  1085. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1086. # 插入空行
  1087. time.sleep(1)
  1088. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1089. # 视频信息写入监控表
  1090. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1091. v_id,
  1092. v_title,
  1093. our_video_link,
  1094. p_id,
  1095. p_mid,
  1096. hour_user_name,
  1097. int(hour_video_duration) / 1000,
  1098. time.strftime("%Y/%m/%d %H:%M:%S",
  1099. time.localtime(int(hour_video_send_time) / 1000)),
  1100. hour_play_cnt]]
  1101. time.sleep(1)
  1102. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1103. except Exception as e:
  1104. Common.logger(log_type).error("下载视频异常:{}", e)
  1105. elif int(fifteen_cnt) >= 2000 and int(twenty_cnt) >= 2000:
  1106. Common.logger(log_type).info(
  1107. "15:00 and 20:00 数据上升量:{} and {} >= 2000", fifteen_cnt, twenty_cnt)
  1108. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1109. try:
  1110. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1111. headers = {
  1112. "x-b3-traceid": cls.hour_x_b3_traceid,
  1113. "X-Token-Id": cls.hour_x_token_id,
  1114. "uid": cls.hour_uid,
  1115. "content-type": "application/json",
  1116. "Accept-Encoding": "gzip,compress,br,deflate",
  1117. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1118. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1119. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1120. "Referer": cls.hour_referer
  1121. }
  1122. data = {
  1123. "play_src": "1",
  1124. "profile_id": int(p_id),
  1125. "profile_mid": int(p_mid),
  1126. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1127. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1128. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1129. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1130. "share_width": 625,
  1131. "share_height": 500,
  1132. "no_comments": True,
  1133. "no_follow": True,
  1134. "vid": v_id,
  1135. "hot_l1_comment": True,
  1136. "token": cls.hour_token,
  1137. "uid": cls.hour_uid,
  1138. "proj": "ma",
  1139. "wx_ver": "8.0.20",
  1140. "code_ver": "3.62.0",
  1141. "log_common_params": {
  1142. "e": [{
  1143. "data": {
  1144. "page": "dynamicSharePage"
  1145. }
  1146. }],
  1147. "ext": {
  1148. "brand": "iPhone",
  1149. "device": "iPhone 11",
  1150. "os": "iOS 14.7.1",
  1151. "weixinver": "8.0.20",
  1152. "srcver": "2.24.3",
  1153. "net": "wifi",
  1154. "scene": "1089"
  1155. },
  1156. "pj": "1",
  1157. "pf": "2",
  1158. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1159. }
  1160. }
  1161. urllib3.disable_warnings()
  1162. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1163. hour_play_cnt = r.json()["data"]["play_pv"]
  1164. hour_cover_url = r.json()["data"]["url"]
  1165. hour_video_url = r.json()["data"]["v_url"]
  1166. hour_video_duration = r.json()["data"]["du"]
  1167. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1168. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1169. hour_video_share_cnt = r.json()["data"]["share"]
  1170. hour_video_width = r.json()["data"]["w"]
  1171. hour_video_height = r.json()["data"]["h"]
  1172. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1173. hour_video_send_time = r.json()["data"]["t"]
  1174. hour_user_name = r.json()["data"]["user"]["nick"]
  1175. hour_head_url = r.json()["data"]["user"]["hurl"]
  1176. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1177. # 下载封面
  1178. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1179. # 下载视频
  1180. Common.download_method(log_type, "video", v_title, hour_video_url)
  1181. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1182. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1183. f_a.write(str(v_id) + "\n" +
  1184. str(v_title) + "\n" +
  1185. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1186. str(hour_play_cnt) + "\n" +
  1187. str(hour_video_comment_cnt) + "\n" +
  1188. str(hour_video_like_cnt) + "\n" +
  1189. str(hour_video_share_cnt) + "\n" +
  1190. str(hour_video_resolution) + "\n" +
  1191. str(hour_video_send_time) + "\n" +
  1192. str(hour_user_name) + "\n" +
  1193. str(hour_head_url) + "\n" +
  1194. str(hour_video_url) + "\n" +
  1195. str(hour_cover_url) + "\n" +
  1196. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1197. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1198. # 上传
  1199. Common.logger(log_type).info("开始上传视频")
  1200. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1201. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1202. our_video_id) + "/info"
  1203. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1204. # 上传完成时间
  1205. upload_time = int(time.time())
  1206. # 保存视频信息到云文档
  1207. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1208. # 插入空行
  1209. time.sleep(1)
  1210. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1211. # 视频信息写入云文档
  1212. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(upload_time))),
  1213. "小时级上升榜",
  1214. v_id,
  1215. v_title,
  1216. our_video_link,
  1217. hour_play_cnt,
  1218. hour_video_comment_cnt,
  1219. hour_video_like_cnt,
  1220. hour_video_share_cnt,
  1221. int(hour_video_duration) / 1000,
  1222. hour_video_resolution,
  1223. time.strftime("%Y-%m-%d %H:%M:%S",
  1224. time.localtime(int(hour_video_send_time) / 1000)),
  1225. hour_user_name,
  1226. p_id,
  1227. p_mid,
  1228. hour_head_url,
  1229. hour_cover_url,
  1230. hour_video_url]]
  1231. time.sleep(1)
  1232. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1233. # 保存视频信息到监控表
  1234. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1235. # 插入空行
  1236. time.sleep(1)
  1237. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1238. # 视频信息写入监控表
  1239. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1240. v_id,
  1241. v_title,
  1242. our_video_link,
  1243. p_id,
  1244. p_mid,
  1245. hour_user_name,
  1246. int(hour_video_duration) / 1000,
  1247. time.strftime("%Y/%m/%d %H:%M:%S",
  1248. time.localtime(int(hour_video_send_time) / 1000)),
  1249. hour_play_cnt]]
  1250. time.sleep(1)
  1251. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1252. except Exception as e:
  1253. Common.logger(log_type).error("下载视频异常:{}", e)
  1254. elif int(yesterday_twenty_cnt) >= 2000 and int(ten_cnt) >= 2000:
  1255. Common.logger(log_type).info("昨日20:00 and 今日10:00 数据上升量:{} and {} >= 2000",
  1256. yesterday_twenty_cnt, ten_cnt)
  1257. Common.logger(log_type).info("满足下载规则,开始下载视频")
  1258. try:
  1259. url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
  1260. headers = {
  1261. "x-b3-traceid": cls.hour_x_b3_traceid,
  1262. "X-Token-Id": cls.hour_x_token_id,
  1263. "uid": cls.hour_uid,
  1264. "content-type": "application/json",
  1265. "Accept-Encoding": "gzip,compress,br,deflate",
  1266. "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
  1267. ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
  1268. 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
  1269. "Referer": cls.hour_referer
  1270. }
  1271. data = {
  1272. "play_src": "1",
  1273. "profile_id": int(p_id),
  1274. "profile_mid": int(p_mid),
  1275. "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
  1276. "!400x400r/crop/400x400/interlace/1/format/jpg",
  1277. "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
  1278. "/!80x80r/crop/80x80/interlace/1/format/jpg",
  1279. "share_width": 625,
  1280. "share_height": 500,
  1281. "no_comments": True,
  1282. "no_follow": True,
  1283. "vid": v_id,
  1284. "hot_l1_comment": True,
  1285. "token": cls.hour_token,
  1286. "uid": cls.hour_uid,
  1287. "proj": "ma",
  1288. "wx_ver": "8.0.20",
  1289. "code_ver": "3.62.0",
  1290. "log_common_params": {
  1291. "e": [{
  1292. "data": {
  1293. "page": "dynamicSharePage"
  1294. }
  1295. }],
  1296. "ext": {
  1297. "brand": "iPhone",
  1298. "device": "iPhone 11",
  1299. "os": "iOS 14.7.1",
  1300. "weixinver": "8.0.20",
  1301. "srcver": "2.24.3",
  1302. "net": "wifi",
  1303. "scene": "1089"
  1304. },
  1305. "pj": "1",
  1306. "pf": "2",
  1307. "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
  1308. }
  1309. }
  1310. urllib3.disable_warnings()
  1311. r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
  1312. hour_play_cnt = r.json()["data"]["play_pv"]
  1313. hour_cover_url = r.json()["data"]["url"]
  1314. hour_video_url = r.json()["data"]["v_url"]
  1315. hour_video_duration = r.json()["data"]["du"]
  1316. hour_video_comment_cnt = r.json()["data"]["comment_count"]
  1317. hour_video_like_cnt = r.json()["data"]["favor"]["total"]
  1318. hour_video_share_cnt = r.json()["data"]["share"]
  1319. hour_video_width = r.json()["data"]["w"]
  1320. hour_video_height = r.json()["data"]["h"]
  1321. hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
  1322. hour_video_send_time = r.json()["data"]["t"]
  1323. hour_user_name = r.json()["data"]["user"]["nick"]
  1324. hour_head_url = r.json()["data"]["user"]["hurl"]
  1325. Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
  1326. # 下载封面
  1327. Common.download_method(log_type, "cover", v_title, hour_cover_url)
  1328. # 下载视频
  1329. Common.download_method(log_type, "video", v_title, hour_video_url)
  1330. # 保存视频信息至 "./videos/{download_video_title}/info.txt"
  1331. with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
  1332. f_a.write(str(v_id) + "\n" +
  1333. str(v_title) + "\n" +
  1334. str(int(int(hour_video_duration) / 1000)) + "\n" +
  1335. str(hour_play_cnt) + "\n" +
  1336. str(hour_video_comment_cnt) + "\n" +
  1337. str(hour_video_like_cnt) + "\n" +
  1338. str(hour_video_share_cnt) + "\n" +
  1339. str(hour_video_resolution) + "\n" +
  1340. str(hour_video_send_time) + "\n" +
  1341. str(hour_user_name) + "\n" +
  1342. str(hour_head_url) + "\n" +
  1343. str(hour_video_url) + "\n" +
  1344. str(hour_cover_url) + "\n" +
  1345. str("90747742180aeb22c0fe3a3c6a38f3d9"))
  1346. Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
  1347. # 上传
  1348. Common.logger(log_type).info("开始上传视频")
  1349. our_video_id = Publish.upload_and_publish(log_type, "prod", "up")
  1350. our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
  1351. our_video_id) + "/info"
  1352. Common.logger(log_type).info("视频上传完成:{}", v_title)
  1353. # 上传完成时间
  1354. upload_time = int(time.time())
  1355. # 保存视频信息到云文档
  1356. Common.logger(log_type).info("添加视频到云文档:{}", v_title)
  1357. # 插入空行
  1358. time.sleep(1)
  1359. Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
  1360. # 视频信息写入云文档
  1361. values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(upload_time))),
  1362. "小时级上升榜",
  1363. v_id,
  1364. v_title,
  1365. our_video_link,
  1366. hour_play_cnt,
  1367. hour_video_comment_cnt,
  1368. hour_video_like_cnt,
  1369. hour_video_share_cnt,
  1370. int(hour_video_duration) / 1000,
  1371. hour_video_resolution,
  1372. time.strftime("%Y-%m-%d %H:%M:%S",
  1373. time.localtime(int(hour_video_send_time) / 1000)),
  1374. hour_user_name,
  1375. p_id,
  1376. p_mid,
  1377. hour_head_url,
  1378. hour_cover_url,
  1379. hour_video_url]]
  1380. time.sleep(1)
  1381. Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
  1382. # 保存视频信息到监控表
  1383. Common.logger(log_type).info("添加视频到监控表:{}", v_title)
  1384. # 插入空行
  1385. time.sleep(1)
  1386. Feishu.insert_columns(log_type, "monitor", "N7e2yI", "ROWS", 1, 2)
  1387. # 视频信息写入监控表
  1388. values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
  1389. v_id,
  1390. v_title,
  1391. our_video_link,
  1392. p_id,
  1393. p_mid,
  1394. hour_user_name,
  1395. int(hour_video_duration) / 1000,
  1396. time.strftime("%Y/%m/%d %H:%M:%S",
  1397. time.localtime(int(hour_video_send_time) / 1000)),
  1398. hour_play_cnt]]
  1399. time.sleep(1)
  1400. Feishu.update_values(log_type, "monitor", "N7e2yI", "F2:O2", values)
  1401. except Exception as e:
  1402. Common.logger(log_type).error("下载视频异常:{}", e)
  1403. else:
  1404. Common.logger(log_type).info("上升量不满足下载规则")
  1405. except Exception as e:
  1406. Common.logger(log_type).error("下载视频时,获取飞书信息异常:{}", e)
  1407. if __name__ == "__main__":
  1408. hour_list = HourList()
  1409. # hour_list.get_hour_list_feeds()
  1410. # hour_list.del_null_rows("xiaoniangao", "ba0da4", 3)
  1411. # hour_list.update_hour_list_data(
  1412. # today=datetime.datetime.now().strftime("%Y-%m-%d"),
  1413. # yesterday=(datetime.date.today() + datetime.timedelta(days=-1)).strftime("%Y-%m-%d"),
  1414. # before_yesterday=(datetime.date.today() + datetime.timedelta(days=-2)).strftime("%Y-%m-%d"))
  1415. # hour_list.download_and_publish("hour")
  1416. hour_list.update_hour_list_data("hour", "2022-07-01", "2022-06-30", "2022-06-29")