hour_list.py 90 KB

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