12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484 |
- # -*- coding: utf-8 -*-
- # @Author: wangkun
- # @Time: 2022/5/16
- import datetime
- import os
- import random
- import sys
- import time
- import requests
- import urllib3
- sys.path.append(os.getcwd())
- from main.common import Common
- from main.feishu_lib import Feishu
- from main.xiaoniangao_publish import Publish
- proxies = {"http": None, "https": None}
- class HourList:
- # 配置微信
- time.sleep(1)
- wechat_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "dzcWHw")
- hour_x_b3_traceid = wechat_sheet[2][1]
- hour_x_token_id = wechat_sheet[3][1]
- hour_referer = wechat_sheet[4][1]
- hour_uid = wechat_sheet[5][1]
- hour_token = wechat_sheet[6][1]
- # 生成 uid、token
- @classmethod
- def get_uid_token(cls):
- uid_token = "abcdefghijklmnopqrstuvwxyz0123456789"
- uid = ("".join(random.sample(uid_token, 8))) + "-" + ("".join(random.sample(uid_token, 4))) + "-" + (
- "".join(random.sample(uid_token, 4))) + "-" + ("".join(random.sample(uid_token, 4))) + "-" + (
- "".join(random.sample(uid_token, 12)))
- token = ("".join(random.sample(uid_token, 32)))
- Feishu.update_values("hour", "xiaoniangao", "dzcWHw", "B6:B6", [[uid]])
- time.sleep(1)
- Feishu.update_values("hour", "xiaoniangao", "dzcWHw", "B7:B7", [[token]])
- Common.logger("hour").info("生成 uid:{}, token:{},写入飞书成功\n", uid, token)
- # 过滤敏感词
- @classmethod
- def sensitive_words(cls, log_type):
- # 敏感词库列表
- word_list = []
- # 从云文档读取所有敏感词,添加到词库列表
- time.sleep(1)
- lists = Feishu.get_values_batch(log_type, "xiaoniangao", "DRAnZh")
- for i in lists:
- for j in i:
- # 过滤空的单元格内容
- if j is None:
- pass
- else:
- word_list.append(j)
- return word_list
- # 视频ID过滤字母
- @classmethod
- def sensitive_videoid_words(cls):
- # 字母列表
- words_list = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
- "t", "u", "v", "w", "x", "y", "z",
- "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
- "T", "U", "V", "W", "X", "Y", "Z"]
- return words_list
- # 基础门槛规则
- @staticmethod
- def download_rule(d_duration, d_width, d_height, d_play_cnt, d_like_cnt, d_share_cnt, d_send_time):
- """
- 下载视频的基本规则
- :param d_duration: 时长
- :param d_width: 宽
- :param d_height: 高
- :param d_play_cnt: 播放量
- :param d_like_cnt: 点赞量
- :param d_share_cnt: 分享量
- :param d_send_time: 发布时间
- :return: 满足规则,返回 True;反之,返回 False
- """
- # 视频时长
- if int(float(d_duration)) >= 40:
- # 宽或高
- if int(d_width) >= 0 or int(d_height) >= 0:
- # 播放量
- if int(d_play_cnt) >= 4000:
- # 点赞量
- if int(d_like_cnt) >= 0:
- # 分享量
- if int(d_share_cnt) >= 0:
- # 发布时间 <= 10 天
- if int(time.time()) - int(d_send_time) / 1000 <= 864000:
- return True
- else:
- return False
- else:
- return False
- else:
- return False
- else:
- return False
- return False
- return False
- # 检查是否有今日的上升榜日期
- @classmethod
- def check_hour_list_data(cls, log_type, date):
- # 判断J1单元格的日期是否为今天
- time.sleep(1)
- if Feishu.get_range_value(log_type, "xiaoniangao", "ba0da4", "L1:L1")[0] != date:
- # 插入3列 L1:N1,并写入日期和时间数据
- values = [[date], ["10:00", "15:00", "20:00"]]
- time.sleep(1)
- Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "COLUMNS", 11, 14)
- time.sleep(1)
- Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "L1:N2", values)
- time.sleep(1)
- Feishu.merge_cells(log_type, "xiaoniangao", "ba0da4", "L1:N1")
- Common.logger(log_type).info("插入今天日期成功")
- else:
- Common.logger(log_type).info("今日上升榜日期已存在")
- # 获取表情及符号
- @classmethod
- def get_expression(cls):
- expression_list = []
- char_list = []
- char_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "BhlbST")
- for i in range(len(char_sheet)):
- if char_sheet[i][0] is not None:
- expression_list.append(char_sheet[i][0])
- if char_sheet[i][1] is not None:
- char_list.append(char_sheet[i][1])
- # print(f"expression_list:{expression_list}")
- # print(f"char_list:{char_list}")
- return expression_list, char_list
- # 获取列表
- @classmethod
- def get_hour_list_feeds(cls, log_type):
- """
- 1.从列表获取视频,7 天内,播放量>=5000
- 2.时长 1-10min
- 3.每天10:00、15:00、20:00 把符合规则的视频,写入云文档
- https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
- """
- url = "https://kapi.xiaoniangao.cn/trends/get_recommend_trends"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "log_params": {
- "page": "discover_rec",
- "common": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.2",
- "net": "wifi",
- "scene": 1089
- }
- },
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!750x500r/crop/750x500/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "ext": {
- "fmid": 0,
- "items": {}
- },
- "app": "xng",
- "rec_scene": "discover_rec",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "discoverIndexPage",
- "topic": "recommend"
- },
- "ab": {}
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- },
- "refresh": False,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0"
- }
- try:
- urllib3.disable_warnings()
- r = requests.post(url=url, headers=headers, json=data, proxies=proxies, verify=False)
- if "data" not in r.json():
- Common.logger(log_type).warning("获取视频feeds错误:{}", r.text)
- elif "list" not in r.json()["data"]:
- Common.logger(log_type).warning("获取视频feeds无数据,休眠10s:{}", r.json()["data"])
- else:
- # 视频列表数据
- feeds = r.json()["data"]["list"]
- for i in range(len(feeds)):
- # 标题,表情随机加在片头、片尾,或替代句子中间的标点符号
- if "title" in feeds[i]:
- befor_video_title = feeds[i]["title"].strip().replace("\n", "") \
- .replace("/", "").replace("\r", "").replace("#", "") \
- .replace(".", "。").replace("\\", "").replace("&NBSP", "") \
- .replace(":", "").replace("*", "").replace("?", "") \
- .replace("?", "").replace('"', "").replace("<", "") \
- .replace(">", "").replace("|", "").replace(" ", "").replace("#表情", "").replace("#符号", "")
- expression = cls.get_expression()
- expression_list = expression[0]
- char_list = expression[1]
- # 随机取一个表情
- expression = random.choice(expression_list)
- # 生成标题list[表情+title, title+表情]
- expression_title_list = [expression + befor_video_title, befor_video_title + expression]
- # 从标题list中随机取一个标题
- title_list1 = random.choice(expression_title_list)
- # 生成标题:原标题+符号
- title_list2 = befor_video_title + random.choice(char_list)
- # 表情和标题组合,与标题和符号组合,汇总成待使用的标题列表
- title_list4 = [title_list2, title_list1]
- # 最终标题
- video_title = random.choice(title_list4)
- else:
- video_title = 0
- # 视频 ID
- if "vid" in feeds[i]:
- video_id = feeds[i]["vid"]
- else:
- video_id = 0
- # 播放量
- if "play_pv" in feeds[i]:
- video_play_cnt = feeds[i]["play_pv"]
- else:
- video_play_cnt = 0
- # 点赞量
- if "favor" in feeds[i]:
- video_like_cnt = feeds[i]["favor"]["total"]
- else:
- video_like_cnt = 0
- # 分享量
- if "share" in feeds[i]:
- video_share_cnt = feeds[i]["share"]
- else:
- video_share_cnt = 0
- # 时长
- if "du" in feeds[i]:
- video_duration = int(feeds[i]["du"] / 1000)
- else:
- video_duration = 0
- # 宽和高
- if "w" or "h" in feeds[i]:
- video_width = feeds[i]["w"]
- video_height = feeds[i]["h"]
- else:
- video_width = 0
- video_height = 0
- # 发布时间
- if "t" in feeds[i]:
- video_send_time = feeds[i]["t"]
- else:
- video_send_time = 0
- # 用户名 / 头像
- if "user" in feeds[i]:
- user_name = feeds[i]["user"]["nick"].strip().replace("\n", "") \
- .replace("/", "").replace("快手", "").replace(" ", "") \
- .replace(" ", "").replace("&NBSP", "").replace("\r", "")
- head_url = feeds[i]["user"]["hurl"]
- else:
- user_name = 0
- head_url = 0
- # 用户 ID
- profile_id = feeds[i]["id"]
- # 用户 mid
- profile_mid = feeds[i]["user"]["mid"]
- # 视频封面
- if "url" in feeds[i]:
- cover_url = feeds[i]["url"]
- else:
- cover_url = 0
- # 视频播放地址
- if "v_url" in feeds[i]:
- video_url = feeds[i]["v_url"]
- else:
- video_url = 0
- Common.logger(log_type).info("标题:{}", video_title)
- Common.logger(log_type).info("视频ID:{}", video_id)
- Common.logger(log_type).info("播放量:{}", video_play_cnt)
- Common.logger(log_type).info("时长:{}秒", video_duration)
- Common.logger(log_type).info(
- "视频发布时间:{}", time.strftime(
- "%Y/%m/%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
- Common.logger(log_type).info("用户名:{}", user_name)
- Common.logger(log_type).info("播放地址:{}", video_url)
- # 过滤无效视频
- if video_title == 0 or video_id == 0 or video_duration == 0 \
- or video_send_time == 0 or user_name == 0 or head_url == 0 \
- or cover_url == 0 or video_url == 0:
- Common.logger(log_type).warning("无效视频")
- # 抓取基础规则过滤
- elif cls.download_rule(video_duration, video_width, video_height, video_play_cnt,
- video_like_cnt, video_share_cnt, video_send_time) is False:
- Common.logger(log_type).info("不满足基础门槛规则")
- # 过滤敏感词
- elif any(str(word) if str(word) in video_title else False for word in cls.sensitive_words(log_type)) is True:
- Common.logger(log_type).info("视频已中敏感词:{}".format(video_title))
- time.sleep(1)
- # 从云文档中去重: 小时级_已下载表
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "InCA1I") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "66n2um") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- # 从云文档中去重: 用户主页_已下载表
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "Wu0CeL") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "bkIrcr") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "FcQ4MN") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "zI9QJz") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- # 从云文档去重: 播放量_已下载表
- elif video_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "c85k1C") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", video_title)
- # 从云文档去重: 小年糕小时级数据_feeds
- elif video_id in [j for i in Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4") for j in i]:
- Common.logger(log_type).info("该视频已保存过:{}", video_title)
- else:
- # feeds工作表,插入空行
- Feishu.insert_columns(log_type, "xiaoniangao", "ba0da4", "ROWS", 2, 3)
- # 获取当前时间
- get_feeds_time = int(time.time())
- # 看一看云文档,工作表中写入数据
- values = [[profile_id,
- profile_mid,
- video_id,
- video_title,
- user_name,
- video_duration,
- cover_url,
- video_url,
- time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)),
- str(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(get_feeds_time))),
- video_play_cnt]]
- # 等待 1s,防止操作云文档太频繁,导致报错
- time.sleep(0.5)
- Feishu.update_values(log_type, "xiaoniangao", "ba0da4", "A3:K3", values)
- Common.logger(log_type).info("视频添加至小时级数据_feeds成功:{}\n".format(video_title))
- except Exception as e:
- Common.logger(log_type).error("获取小时榜视频列表异常:{}\n", e)
- # 更新小时榜数据
- @classmethod
- def update_hour_list_data(cls, log_type, today, yesterday, before_yesterday):
- """
- 更新小时榜数据
- """
- try:
- update_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
- if len(update_hour_sheet) == 2:
- Common.logger(log_type).info("当前工作表无数据")
- else:
- for i in range(2, len(update_hour_sheet) + 1):
- Common.logger(log_type).info("更新第:{}行视频信息", i + 1)
- # 略过空行
- if update_hour_sheet[i][0] is None \
- or update_hour_sheet[i][1] is None or update_hour_sheet[i][2] is None:
- Common.logger(log_type).info("空行,略过")
- else:
- # 视频标题
- v_title = update_hour_sheet[i][3]
- Common.logger(log_type).info("video_title:{}", v_title)
- # 视频 ID
- v_id = update_hour_sheet[i][2]
- Common.logger(log_type).info("video_id:{}", v_id)
- # profile_id,用户 ID
- p_id = update_hour_sheet[i][0]
- Common.logger(log_type).info("profile_id:{}", p_id)
- # profile_mid
- p_mid = update_hour_sheet[i][1]
- Common.logger(log_type).info("profile_mid:{}", p_mid)
- # 抓取时的播放量
- v_play_cnt = update_hour_sheet[i][10]
- Common.logger(log_type).info("video_play_cnt:{}", v_play_cnt)
- # 抓取时间
- v_upload_time = update_hour_sheet[i][9]
- Common.logger(log_type).info("video_send_time:{}", v_upload_time)
- # 抓取时间的时间戳格式(秒为单位)
- v_time = int(time.mktime(time.strptime(v_upload_time, "%Y/%m/%d %H:%M:%S")))
- # 抓取时间:日期
- upload_data = v_upload_time.split(" ")[0]
- # 抓取时间:小时
- upload_hour = v_upload_time.split(" ")[-1].split(":")[0]
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "play_src": "1",
- "profile_id": int(p_id),
- "profile_mid": int(p_mid),
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
- "!400x400r/crop/400x400/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
- "/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "no_comments": True,
- "no_follow": True,
- "vid": v_id,
- "hot_l1_comment": True,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "dynamicSharePage"
- }
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- }
- }
- try:
- urllib3.disable_warnings()
- r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
- hour_play_cnt = r.json()["data"]["play_pv"]
- Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
- # 固定时间获取符合规则的视频,写入云文档:https://w42nne6hzg.feishu.cn/sheets/shtcngRPoDYAi24x52j2nDuHMih?sheet=ba0da4
- update_hour = datetime.datetime.now()
- if int(time.time()) - v_time >= 172800:
- Common.logger(log_type).info("抓取时间超过 2 天")
- return
- elif upload_data == today and update_hour.hour == 10 and int(upload_hour) <= 10:
- Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:10点 and 抓取时间<=10点")
- # 当天 10:00 视频播放量
- ten_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
- # 10:00 的上升榜写入数据
- values = int(ten_hour_play_cnt) - int(v_play_cnt)
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "L" + str(i + 1) + ":" + "L" + str(i + 1), [[values]])
- Common.logger(log_type).info("10:00数据更新成功:{}", values)
- elif upload_data == today and update_hour.hour == 15 and int(upload_hour) <= 10:
- Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 抓取时间<=10点")
- # 当天 15:00 视频播放量
- fifteen_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
- # 当天 10:00 上升的数据
- if update_hour_sheet[i][11] is None:
- ten_up_cnt = 0
- else:
- ten_up_cnt = update_hour_sheet[i][11]
- # 15:00 的上升榜写入数据
- values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
- Common.logger(log_type).info("15:00数据更新成功:{}", values)
- elif upload_data == today and update_hour.hour == 15 and 10 < int(upload_hour) <= 15:
- Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:15点 and 10<抓取时间<=15点")
- # 当天 15:00 视频播放量
- fifteen_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
- # 15:00 的上升榜写入数据
- values = int(fifteen_hour_play_cnt) - int(v_play_cnt)
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
- Common.logger(log_type).info("15:00数据更新成功:{}", values)
- elif upload_data == today and update_hour.hour == 20 and int(upload_hour) <= 10:
- Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 抓取时间<=10点")
- # 当天 20:00 视频播放量
- twenty_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
- # 当天 10:00 上升的数据
- if update_hour_sheet[i][11] is None:
- ten_up_cnt = 0
- else:
- ten_up_cnt = update_hour_sheet[i][11]
- # 当天 15:00 上升的数据
- if update_hour_sheet[i][12] is None:
- fifteen_up_cnt = 0
- else:
- fifteen_up_cnt = update_hour_sheet[i][12]
- # 20:00 的上升榜写入数据
- values = int(twenty_hour_play_cnt) - (
- int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
- Common.logger(log_type).info("20:00数据更新成功:{}", values)
- elif upload_data == today and update_hour.hour == 20 and 10 < int(upload_hour) <= 15:
- Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 10<抓取时间<=15点")
- # 当天 20:00 视频播放量
- twenty_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
- # 当天 15:00 上升的数据
- if update_hour_sheet[i][12] is None:
- fifteen_up_cnt = 0
- else:
- fifteen_up_cnt = update_hour_sheet[i][12]
- # 20:00 的上升榜写入数据
- values = int(twenty_hour_play_cnt) - (int(v_play_cnt) + int(fifteen_up_cnt))
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
- Common.logger(log_type).info("20:00数据更新成功:{}", values)
- elif upload_data == today and update_hour.hour == 20 and 15 < int(upload_hour) <= 20:
- Common.logger(log_type).info("满足条件: 抓取日期为今天 and 当前时间:20点 and 15<抓取时间<=20点")
- # 当天 20:00 视频播放量
- twenty_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
- # 20:00 的上升榜写入数据
- values = int(twenty_hour_play_cnt) - int(v_play_cnt)
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
- Common.logger(log_type).info("20:00数据更新成功:{}", values)
- elif (upload_data == yesterday or upload_data == before_yesterday) \
- and update_hour.hour == 10:
- Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:10点")
- # 当天 10:00 视频播放量
- ten_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 10:00 视频播放量:{}", ten_hour_play_cnt)
- # 10:00 的上升榜写入数据
- values = int(ten_hour_play_cnt) - int(v_play_cnt)
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "L" + str(i + 1) + ":" + "L" + str(i + 1), [[values]])
- Common.logger(log_type).info("10:00数据更新成功:{}", values)
- elif (upload_data == yesterday or upload_data == before_yesterday) \
- and update_hour.hour == 15:
- Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:15点")
- # 当天 15:00 视频播放量
- fifteen_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 15:00 视频播放量:{}", fifteen_hour_play_cnt)
- # 当天 10:00 上升的数据
- if update_hour_sheet[i][11] is None:
- ten_up_cnt = 0
- else:
- ten_up_cnt = update_hour_sheet[i][11]
- # 15:00 的上升榜写入数据
- values = int(fifteen_hour_play_cnt) - (int(v_play_cnt) + int(ten_up_cnt))
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "M" + str(i + 1) + ":" + "M" + str(i + 1), [[values]])
- Common.logger(log_type).info("15:00数据更新成功:{}", values)
- elif (upload_data == yesterday or upload_data == before_yesterday) \
- and update_hour.hour == 20:
- Common.logger(log_type).info("满足条件: 抓取时间小于今天 and 当前时间:20点")
- # 当天 20:00 视频播放量
- twenty_hour_play_cnt = hour_play_cnt
- Common.logger(log_type).info("当天 20:00 视频播放量:{}", twenty_hour_play_cnt)
- # 当天 10:00 上升的数据
- if update_hour_sheet[i][11] is None:
- ten_up_cnt = 0
- else:
- ten_up_cnt = update_hour_sheet[i][11]
- # 当天 15:00 上升的数据
- if update_hour_sheet[i][12] is None:
- fifteen_up_cnt = 0
- else:
- fifteen_up_cnt = update_hour_sheet[i][12]
- # 20:00 的上升榜写入数据
- values = int(twenty_hour_play_cnt) - (
- int(v_play_cnt) + int(ten_up_cnt) + int(fifteen_up_cnt))
- time.sleep(1)
- Feishu.update_values(
- log_type, "xiaoniangao", "ba0da4",
- "N" + str(i + 1) + ":" + "N" + str(i + 1), [[values]])
- Common.logger(log_type).info("20:00数据更新成功:{}", values)
- except Exception as e:
- Common.logger(log_type).error("视频详情:{},异常:{}", v_title, e)
- except Exception as e:
- Common.logger(log_type).error("获取小时榜数据异常:{}\n", e)
- # 下载/上传
- @classmethod
- def download_and_publish(cls, log_type):
- """
- 1.从云文档中去重: https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=yatRv2
- 2.从云文档中下载符合规则的视频:https://w42nne6hzg.feishu.cn/sheets/shtcnYxiyQ1wLklo1W5Kdqc9cGh?sheet=ba0da4
- 2.1 当日 10:00 or 15:00 or 20:00 视频播放量上升 > 5000
- 2.2 当日 10:00 and 15:00 视频播放量上升 > 2000
- 2.3 当日 15:00 and 20:00 视频播放量上升 > 2000
- 2.4 昨日 20:00 and 今日 10:00 视频播放量上升 > 2000
- 3.上传
- """
- try:
- time.sleep(1)
- download_hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
- if len(download_hour_sheet) == 2:
- Common.logger(log_type).info("当前工作表无数据")
- else:
- for i in range(2, len(download_hour_sheet) + 1):
- Common.logger(log_type).info("分析第:{}行视频信息是否符合下载规则", i + 1)
- # 略过空行
- if download_hour_sheet[i][0] is None \
- or download_hour_sheet[i][1] is None or download_hour_sheet[i][2] is None:
- Common.logger(log_type).info("空行,略过")
- else:
- # 今日 10:00 数据上升量
- if download_hour_sheet[i][11] is None:
- ten_cnt = 0
- else:
- ten_cnt = download_hour_sheet[i][11]
- # 今日 15:00 数据上升量
- if download_hour_sheet[i][12] is None:
- fifteen_cnt = 0
- else:
- fifteen_cnt = download_hour_sheet[i][12]
- # 今日 20:00 数据上升量
- if download_hour_sheet[i][13] is None:
- twenty_cnt = 0
- else:
- twenty_cnt = download_hour_sheet[i][13]
- # 昨日 20:00 数据上升量
- if download_hour_sheet[i][16] is None:
- yesterday_twenty_cnt = 0
- else:
- yesterday_twenty_cnt = download_hour_sheet[i][16]
- # 视频标题
- v_title = download_hour_sheet[i][3]
- Common.logger(log_type).info("video_title:{}", v_title)
- # 视频 ID
- v_id = download_hour_sheet[i][2]
- Common.logger(log_type).info("video_id:{}", v_id)
- # profile_id,用户 ID
- p_id = download_hour_sheet[i][0]
- # 视频时长
- v_duration = download_hour_sheet[i][5]
- # profile_mid
- p_mid = download_hour_sheet[i][1]
- Common.logger(log_type).info("10:00 / 15:00 / 20:00 上升量: {} / {} / {}",
- ten_cnt, fifteen_cnt, twenty_cnt)
- # 抓取时间
- v_upload_time = download_hour_sheet[i][9]
- v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y/%m/%d %H:%M:%S")))
- # 播放量
- v_play_cnt = download_hour_sheet[i][10]
- # # 判断视频 ID 长度,不大于 13 位
- # if len(str(v_id)) > 13:
- # Common.logger(log_type).info("视频ID长度大于13位:{}", v_id)
- #
- # el
- if int(time.time()) - int(v_send_time) >= 259200:
- Common.logger(log_type).info("抓取时间超过 3 天")
- return
- # 判断视频时长:1-10min
- elif int(v_duration) < 40:
- Common.logger(log_type).info("视频时长小于 40s")
- # # 过滤带字母的视频ID
- # elif any(word if word in v_id else False for word in cls.sensitive_videoid_words()) is True:
- # Common.logger(log_type).info("视频ID带字母:{}".format(v_id))
- # 从云文档中去重: 小时级_已下载表
- elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "yatRv2") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", v_title)
- elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "InCA1I") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", v_title)
- # 从云文档中去重: 用户主页_已下载表
- elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "Wu0CeL") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", v_title)
- elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "bkIrcr") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", v_title)
- # 从云文档中去重: 播放量_已下载表
- elif v_id in [j for i in Feishu.get_values_batch(log_type, "xiaoniangao", "c85k1C") for j in i]:
- Common.logger(log_type).info("该视频已下载:{}", v_title)
- # 播放量大于 50000,直接下载
- elif int(v_play_cnt) >= 50000:
- Common.logger(log_type).info("播放量:{} >= 50000,满足下载规则,开始下载视频", v_play_cnt)
- try:
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "play_src": "1",
- "profile_id": int(p_id),
- "profile_mid": int(p_mid),
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
- "!400x400r/crop/400x400/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
- "/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "no_comments": True,
- "no_follow": True,
- "vid": v_id,
- "hot_l1_comment": True,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "dynamicSharePage"
- }
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- }
- }
- urllib3.disable_warnings()
- r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
- hour_play_cnt = r.json()["data"]["play_pv"]
- hour_cover_url = r.json()["data"]["url"]
- hour_video_url = r.json()["data"]["v_url"]
- hour_video_duration = r.json()["data"]["du"]
- hour_video_comment_cnt = r.json()["data"]["comment_count"]
- hour_video_like_cnt = r.json()["data"]["favor"]["total"]
- hour_video_share_cnt = r.json()["data"]["share"]
- hour_video_width = r.json()["data"]["w"]
- hour_video_height = r.json()["data"]["h"]
- hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
- hour_video_send_time = r.json()["data"]["t"]
- hour_user_name = r.json()["data"]["user"]["nick"]
- hour_head_url = r.json()["data"]["user"]["hurl"]
- Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
- # 下载封面
- Common.download_method(log_type, "cover", v_title, hour_cover_url)
- # 下载视频
- Common.download_method(log_type, "video", v_title, hour_video_url)
- # 保存视频信息至 "./videos/{download_video_title}/info.txt"
- with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
- f_a.write(str(v_id) + "\n" +
- str(v_title) + "\n" +
- str(int(int(hour_video_duration) / 1000)) + "\n" +
- str(hour_play_cnt) + "\n" +
- str(hour_video_comment_cnt) + "\n" +
- str(hour_video_like_cnt) + "\n" +
- str(hour_video_share_cnt) + "\n" +
- str(hour_video_resolution) + "\n" +
- str(hour_video_send_time) + "\n" +
- str(hour_user_name) + "\n" +
- str(hour_head_url) + "\n" +
- str(hour_video_url) + "\n" +
- str(hour_cover_url) + "\n" +
- str("90747742180aeb22c0fe3a3c6a38f3d9"))
- Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
- # 上传视频
- Common.logger(log_type).info("开始上传视频")
- our_video_id = Publish.upload_and_publish(log_type, "prod", "hour")
- our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
- our_video_id) + "/info"
- Common.logger(log_type).info("视频上传完成:{}", v_title)
- # 上传完成时间
- upload_time = int(time.time())
- # 保存视频信息到云文档
- Common.logger(log_type).info("添加视频到云文档:{}", v_title)
- # 插入空行
- time.sleep(1)
- Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
- # 视频信息写入云文档
- values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
- "小时级上升榜",
- v_id,
- v_title,
- our_video_link,
- hour_play_cnt,
- hour_video_comment_cnt,
- hour_video_like_cnt,
- hour_video_share_cnt,
- int(hour_video_duration) / 1000,
- hour_video_resolution,
- time.strftime("%Y/%m/%d %H:%M:%S",
- time.localtime(int(hour_video_send_time) / 1000)),
- hour_user_name,
- p_id,
- p_mid,
- hour_head_url,
- hour_cover_url,
- hour_video_url]]
- time.sleep(1)
- Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
- except Exception as e:
- Common.logger(log_type).error("下载视频异常:{}", e)
- # 上升榜判断逻辑,任意时间段上升量>=5000,连续两个时间段上升量>=2000
- elif int(ten_cnt) >= 5000 or int(fifteen_cnt) >= 5000 or int(twenty_cnt) >= 5000:
- Common.logger(log_type).info("10:00 or 15:00 or 20:00 数据上升量:{} or {} or {} >= 5000",
- ten_cnt, fifteen_cnt, twenty_cnt)
- Common.logger(log_type).info("满足下载规则,开始下载视频")
- try:
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "play_src": "1",
- "profile_id": int(p_id),
- "profile_mid": int(p_mid),
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
- "!400x400r/crop/400x400/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
- "/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "no_comments": True,
- "no_follow": True,
- "vid": v_id,
- "hot_l1_comment": True,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "dynamicSharePage"
- }
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- }
- }
- urllib3.disable_warnings()
- r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
- hour_play_cnt = r.json()["data"]["play_pv"]
- hour_cover_url = r.json()["data"]["url"]
- hour_video_url = r.json()["data"]["v_url"]
- hour_video_duration = r.json()["data"]["du"]
- hour_video_comment_cnt = r.json()["data"]["comment_count"]
- hour_video_like_cnt = r.json()["data"]["favor"]["total"]
- hour_video_share_cnt = r.json()["data"]["share"]
- hour_video_width = r.json()["data"]["w"]
- hour_video_height = r.json()["data"]["h"]
- hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
- hour_video_send_time = r.json()["data"]["t"]
- hour_user_name = r.json()["data"]["user"]["nick"]
- hour_head_url = r.json()["data"]["user"]["hurl"]
- Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
- # 下载封面
- Common.download_method(log_type, "cover", v_title, hour_cover_url)
- # 下载视频
- Common.download_method(log_type, "video", v_title, hour_video_url)
- # 保存视频信息至 "./videos/{download_video_title}/info.txt"
- with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
- f_a.write(str(v_id) + "\n" +
- str(v_title) + "\n" +
- str(int(int(hour_video_duration) / 1000)) + "\n" +
- str(hour_play_cnt) + "\n" +
- str(hour_video_comment_cnt) + "\n" +
- str(hour_video_like_cnt) + "\n" +
- str(hour_video_share_cnt) + "\n" +
- str(hour_video_resolution) + "\n" +
- str(hour_video_send_time) + "\n" +
- str(hour_user_name) + "\n" +
- str(hour_head_url) + "\n" +
- str(hour_video_url) + "\n" +
- str(hour_cover_url) + "\n" +
- str("90747742180aeb22c0fe3a3c6a38f3d9"))
- Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
- # 上传视频
- Common.logger(log_type).info("开始上传视频")
- our_video_id = Publish.upload_and_publish(log_type, "prod", "hour")
- our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
- our_video_id) + "/info"
- Common.logger(log_type).info("视频上传完成:{}", v_title)
- # 上传完成时间
- upload_time = int(time.time())
- # 保存视频信息到云文档
- Common.logger(log_type).info("添加视频到云文档:{}", v_title)
- # 插入空行
- time.sleep(1)
- Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
- # 视频信息写入云文档
- values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
- "小时级上升榜",
- v_id,
- v_title,
- our_video_link,
- hour_play_cnt,
- hour_video_comment_cnt,
- hour_video_like_cnt,
- hour_video_share_cnt,
- int(hour_video_duration) / 1000,
- hour_video_resolution,
- time.strftime("%Y/%m/%d %H:%M:%S",
- time.localtime(int(hour_video_send_time) / 1000)),
- hour_user_name,
- p_id,
- p_mid,
- hour_head_url,
- hour_cover_url,
- hour_video_url]]
- time.sleep(1)
- Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
- except Exception as e:
- Common.logger(log_type).error("下载视频异常:{}", e)
- elif int(ten_cnt) >= 2000 and int(fifteen_cnt) >= 2000:
- Common.logger(log_type).info(
- "10:00 and 15:00 数据上升量:{} and {} >= 2000", ten_cnt, fifteen_cnt)
- Common.logger(log_type).info("满足下载规则,开始下载视频")
- try:
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "play_src": "1",
- "profile_id": int(p_id),
- "profile_mid": int(p_mid),
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
- "!400x400r/crop/400x400/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
- "/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "no_comments": True,
- "no_follow": True,
- "vid": v_id,
- "hot_l1_comment": True,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "dynamicSharePage"
- }
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- }
- }
- urllib3.disable_warnings()
- r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
- hour_play_cnt = r.json()["data"]["play_pv"]
- hour_cover_url = r.json()["data"]["url"]
- hour_video_url = r.json()["data"]["v_url"]
- hour_video_duration = r.json()["data"]["du"]
- hour_video_comment_cnt = r.json()["data"]["comment_count"]
- hour_video_like_cnt = r.json()["data"]["favor"]["total"]
- hour_video_share_cnt = r.json()["data"]["share"]
- hour_video_width = r.json()["data"]["w"]
- hour_video_height = r.json()["data"]["h"]
- hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
- hour_video_send_time = r.json()["data"]["t"]
- hour_user_name = r.json()["data"]["user"]["nick"]
- hour_head_url = r.json()["data"]["user"]["hurl"]
- Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
- # 下载封面
- Common.download_method(log_type, "cover", v_title, hour_cover_url)
- # 下载视频
- Common.download_method(log_type, "video", v_title, hour_video_url)
- # 保存视频信息至 "./videos/{download_video_title}/info.txt"
- with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
- f_a.write(str(v_id) + "\n" +
- str(v_title) + "\n" +
- str(int(int(hour_video_duration) / 1000)) + "\n" +
- str(hour_play_cnt) + "\n" +
- str(hour_video_comment_cnt) + "\n" +
- str(hour_video_like_cnt) + "\n" +
- str(hour_video_share_cnt) + "\n" +
- str(hour_video_resolution) + "\n" +
- str(hour_video_send_time) + "\n" +
- str(hour_user_name) + "\n" +
- str(hour_head_url) + "\n" +
- str(hour_video_url) + "\n" +
- str(hour_cover_url) + "\n" +
- str("90747742180aeb22c0fe3a3c6a38f3d9"))
- Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
- # 上传
- Common.logger(log_type).info("开始上传视频")
- our_video_id = Publish.upload_and_publish(log_type, "prod", "hour")
- our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
- our_video_id) + "/info"
- Common.logger(log_type).info("视频上传完成:{}", v_title)
- # 上传完成时间
- upload_time = int(time.time())
- # 保存视频信息到云文档
- Common.logger(log_type).info("添加视频到云文档:{}", v_title)
- # 插入空行
- time.sleep(1)
- Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
- # 视频信息写入云文档
- values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
- "小时级上升榜",
- v_id,
- v_title,
- our_video_link,
- hour_play_cnt,
- hour_video_comment_cnt,
- hour_video_like_cnt,
- hour_video_share_cnt,
- int(hour_video_duration) / 1000,
- hour_video_resolution,
- time.strftime("%Y/%m/%d %H:%M:%S",
- time.localtime(int(hour_video_send_time) / 1000)),
- hour_user_name,
- p_id,
- p_mid,
- hour_head_url,
- hour_cover_url,
- hour_video_url]]
- time.sleep(1)
- Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
- except Exception as e:
- Common.logger(log_type).error("下载视频异常:{}", e)
- elif int(fifteen_cnt) >= 2000 and int(twenty_cnt) >= 2000:
- Common.logger(log_type).info(
- "15:00 and 20:00 数据上升量:{} and {} >= 2000", fifteen_cnt, twenty_cnt)
- Common.logger(log_type).info("满足下载规则,开始下载视频")
- try:
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "play_src": "1",
- "profile_id": int(p_id),
- "profile_mid": int(p_mid),
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
- "!400x400r/crop/400x400/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
- "/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "no_comments": True,
- "no_follow": True,
- "vid": v_id,
- "hot_l1_comment": True,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "dynamicSharePage"
- }
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- }
- }
- urllib3.disable_warnings()
- r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
- hour_play_cnt = r.json()["data"]["play_pv"]
- hour_cover_url = r.json()["data"]["url"]
- hour_video_url = r.json()["data"]["v_url"]
- hour_video_duration = r.json()["data"]["du"]
- hour_video_comment_cnt = r.json()["data"]["comment_count"]
- hour_video_like_cnt = r.json()["data"]["favor"]["total"]
- hour_video_share_cnt = r.json()["data"]["share"]
- hour_video_width = r.json()["data"]["w"]
- hour_video_height = r.json()["data"]["h"]
- hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
- hour_video_send_time = r.json()["data"]["t"]
- hour_user_name = r.json()["data"]["user"]["nick"]
- hour_head_url = r.json()["data"]["user"]["hurl"]
- Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
- # 下载封面
- Common.download_method(log_type, "cover", v_title, hour_cover_url)
- # 下载视频
- Common.download_method(log_type, "video", v_title, hour_video_url)
- # 保存视频信息至 "./videos/{download_video_title}/info.txt"
- with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
- f_a.write(str(v_id) + "\n" +
- str(v_title) + "\n" +
- str(int(int(hour_video_duration) / 1000)) + "\n" +
- str(hour_play_cnt) + "\n" +
- str(hour_video_comment_cnt) + "\n" +
- str(hour_video_like_cnt) + "\n" +
- str(hour_video_share_cnt) + "\n" +
- str(hour_video_resolution) + "\n" +
- str(hour_video_send_time) + "\n" +
- str(hour_user_name) + "\n" +
- str(hour_head_url) + "\n" +
- str(hour_video_url) + "\n" +
- str(hour_cover_url) + "\n" +
- str("90747742180aeb22c0fe3a3c6a38f3d9"))
- Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
- # 上传
- Common.logger(log_type).info("开始上传视频")
- our_video_id = Publish.upload_and_publish(log_type, "prod", "hour")
- our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
- our_video_id) + "/info"
- Common.logger(log_type).info("视频上传完成:{}", v_title)
- # 上传完成时间
- upload_time = int(time.time())
- # 保存视频信息到云文档
- Common.logger(log_type).info("添加视频到云文档:{}", v_title)
- # 插入空行
- time.sleep(1)
- Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
- # 视频信息写入云文档
- values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
- "小时级上升榜",
- v_id,
- v_title,
- our_video_link,
- hour_play_cnt,
- hour_video_comment_cnt,
- hour_video_like_cnt,
- hour_video_share_cnt,
- int(hour_video_duration) / 1000,
- hour_video_resolution,
- time.strftime("%Y/%m/%d %H:%M:%S",
- time.localtime(int(hour_video_send_time) / 1000)),
- hour_user_name,
- p_id,
- p_mid,
- hour_head_url,
- hour_cover_url,
- hour_video_url]]
- time.sleep(1)
- Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
- except Exception as e:
- Common.logger(log_type).error("下载视频异常:{}", e)
- elif int(yesterday_twenty_cnt) >= 2000 and int(ten_cnt) >= 2000:
- Common.logger(log_type).info("昨日20:00 and 今日10:00 数据上升量:{} and {} >= 2000",
- yesterday_twenty_cnt, ten_cnt)
- Common.logger(log_type).info("满足下载规则,开始下载视频")
- try:
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": cls.hour_x_b3_traceid,
- "X-Token-Id": cls.hour_x_token_id,
- "uid": cls.hour_uid,
- "content-type": "application/json",
- "Accept-Encoding": "gzip,compress,br,deflate",
- "User-Agent": 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X)'
- ' AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 '
- 'MicroMessenger/8.0.20(0x18001432) NetType/WIFI Language/zh_CN',
- "Referer": cls.hour_referer
- }
- data = {
- "play_src": "1",
- "profile_id": int(p_id),
- "profile_mid": int(p_mid),
- "qs": "imageMogr2/gravity/center/rotate/$/thumbnail/"
- "!400x400r/crop/400x400/interlace/1/format/jpg",
- "h_qs": "imageMogr2/gravity/center/rotate/$/thumbnail"
- "/!80x80r/crop/80x80/interlace/1/format/jpg",
- "share_width": 625,
- "share_height": 500,
- "no_comments": True,
- "no_follow": True,
- "vid": v_id,
- "hot_l1_comment": True,
- "token": cls.hour_token,
- "uid": cls.hour_uid,
- "proj": "ma",
- "wx_ver": "8.0.20",
- "code_ver": "3.62.0",
- "log_common_params": {
- "e": [{
- "data": {
- "page": "dynamicSharePage"
- }
- }],
- "ext": {
- "brand": "iPhone",
- "device": "iPhone 11",
- "os": "iOS 14.7.1",
- "weixinver": "8.0.20",
- "srcver": "2.24.3",
- "net": "wifi",
- "scene": "1089"
- },
- "pj": "1",
- "pf": "2",
- "session_id": "7bcce313-b57d-4305-8d14-6ebd9a1bad29"
- }
- }
- urllib3.disable_warnings()
- r = requests.post(headers=headers, url=url, json=data, proxies=proxies, verify=False)
- hour_play_cnt = r.json()["data"]["play_pv"]
- hour_cover_url = r.json()["data"]["url"]
- hour_video_url = r.json()["data"]["v_url"]
- hour_video_duration = r.json()["data"]["du"]
- hour_video_comment_cnt = r.json()["data"]["comment_count"]
- hour_video_like_cnt = r.json()["data"]["favor"]["total"]
- hour_video_share_cnt = r.json()["data"]["share"]
- hour_video_width = r.json()["data"]["w"]
- hour_video_height = r.json()["data"]["h"]
- hour_video_resolution = str(hour_video_width) + "*" + str(hour_video_height)
- hour_video_send_time = r.json()["data"]["t"]
- hour_user_name = r.json()["data"]["user"]["nick"]
- hour_head_url = r.json()["data"]["user"]["hurl"]
- Common.logger(log_type).info("视频详情,当前播放量:{}", hour_play_cnt)
- # 下载封面
- Common.download_method(log_type, "cover", v_title, hour_cover_url)
- # 下载视频
- Common.download_method(log_type, "video", v_title, hour_video_url)
- # 保存视频信息至 "./videos/{download_video_title}/info.txt"
- with open("./videos/" + v_title + "/" + "info.txt", "a", encoding="UTF-8") as f_a:
- f_a.write(str(v_id) + "\n" +
- str(v_title) + "\n" +
- str(int(int(hour_video_duration) / 1000)) + "\n" +
- str(hour_play_cnt) + "\n" +
- str(hour_video_comment_cnt) + "\n" +
- str(hour_video_like_cnt) + "\n" +
- str(hour_video_share_cnt) + "\n" +
- str(hour_video_resolution) + "\n" +
- str(hour_video_send_time) + "\n" +
- str(hour_user_name) + "\n" +
- str(hour_head_url) + "\n" +
- str(hour_video_url) + "\n" +
- str(hour_cover_url) + "\n" +
- str("90747742180aeb22c0fe3a3c6a38f3d9"))
- Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
- # 上传
- Common.logger(log_type).info("开始上传视频")
- our_video_id = Publish.upload_and_publish(log_type, "prod", "hour")
- our_video_link = "https://admin.piaoquantv.com/cms/post-detail/" + str(
- our_video_id) + "/info"
- Common.logger(log_type).info("视频上传完成:{}", v_title)
- # 上传完成时间
- upload_time = int(time.time())
- # 保存视频信息到云文档
- Common.logger(log_type).info("添加视频到云文档:{}", v_title)
- # 插入空行
- time.sleep(1)
- Feishu.insert_columns(log_type, "xiaoniangao", "yatRv2", "ROWS", 1, 2)
- # 视频信息写入云文档
- values = [[time.strftime("%Y/%m/%d %H:%M:%S", time.localtime(int(upload_time))),
- "小时级上升榜",
- v_id,
- v_title,
- our_video_link,
- hour_play_cnt,
- hour_video_comment_cnt,
- hour_video_like_cnt,
- hour_video_share_cnt,
- int(hour_video_duration) / 1000,
- hour_video_resolution,
- time.strftime("%Y/%m/%d %H:%M:%S",
- time.localtime(int(hour_video_send_time) / 1000)),
- hour_user_name,
- p_id,
- p_mid,
- hour_head_url,
- hour_cover_url,
- hour_video_url]]
- time.sleep(1)
- Feishu.update_values(log_type, "xiaoniangao", "yatRv2", "F2:W2", values)
- except Exception as e:
- Common.logger(log_type).error("下载视频异常:{}", e)
- else:
- Common.logger(log_type).info("上升量不满足下载规则")
- except Exception as e:
- Common.logger(log_type).error("下载视频时,获取飞书信息异常:{}\n", e)
- if __name__ == "__main__":
- HourList.get_hour_list_feeds("hour")
- pass
|