hour_list.py 91 KB

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