hour_list.py 90 KB

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