hour_list.py 92 KB

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