hour_list.py 92 KB

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