|
@@ -1,13 +1,15 @@
|
|
|
# -*- coding: utf-8 -*-
|
|
|
# @Author: wangkun
|
|
|
# @Time: 2022/5/16
|
|
|
-import datetime
|
|
|
-import random
|
|
|
+import os
|
|
|
+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.publish import Publish
|
|
|
proxies = {"http": None, "https": None}
|
|
|
|
|
|
|
|
@@ -86,243 +88,103 @@ class Demo:
|
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
|
|
|
- # 微信号
|
|
|
@classmethod
|
|
|
- def get_sheet(cls):
|
|
|
- hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")
|
|
|
- # print(hour_sheet)
|
|
|
- print(hour_sheet)
|
|
|
+ def download_publish(cls, log_type, env):
|
|
|
+ # try:
|
|
|
+ play_feeds_sheet = Feishu.get_values_batch(log_type, 'xiaoniangao', 'CtXmf8')
|
|
|
+ for i in range(1, len(play_feeds_sheet)):
|
|
|
+ download_video_title = play_feeds_sheet[i][5]
|
|
|
+ download_video_play_cnt = play_feeds_sheet[i][7]
|
|
|
+ download_video_resolution = play_feeds_sheet[i][8]
|
|
|
+ download_user_name = play_feeds_sheet[i][9]
|
|
|
+ download_user_id = play_feeds_sheet[i][10]
|
|
|
+ download_user_mid = play_feeds_sheet[i][11]
|
|
|
+ download_head_url = play_feeds_sheet[i][12]
|
|
|
+ download_cover_url = play_feeds_sheet[i][12]
|
|
|
+ download_video_url = play_feeds_sheet[i][13]
|
|
|
+
|
|
|
+ Common.logger(log_type).info("正在判断第{}行,视频:{}", i + 1, download_video_title)
|
|
|
+
|
|
|
+ # 过滤空行及空标题视频
|
|
|
+ if download_video_title is None or download_video_title == "":
|
|
|
+ # 删除行或列,可选 ROWS、COLUMNS
|
|
|
+ Feishu.dimension_range(log_type, "xiaoniangao", "CtXmf8", "ROWS", i + 1, i + 1)
|
|
|
+ Common.logger(log_type).warning("标题为空或空行,删除成功\n")
|
|
|
+ return
|
|
|
|
|
|
- @classmethod
|
|
|
- def check_date(cls):
|
|
|
- date = Feishu.get_values_batch("hour", "xiaoniangao", "FEcuil")
|
|
|
- print(f'文档中L1:N1的日期:{date[0][11]}')
|
|
|
- today = datetime.datetime.now().strftime("%Y-%m-%d")
|
|
|
- print(f"today:{today}")
|
|
|
- Common.logger("hour").info("检查今日上升榜日期是否存在")
|
|
|
- if date[0][11] != today:
|
|
|
- # 插入3列 L1:N1,并写入日期和时间数据
|
|
|
- values = [[today], ["10:00", "15:00", "20:00"]]
|
|
|
- time.sleep(1)
|
|
|
- Feishu.insert_columns("hour", "xiaoniangao", "FEcuil", "COLUMNS", 11, 14)
|
|
|
- time.sleep(1)
|
|
|
- Feishu.update_values("hour", "xiaoniangao", "FEcuil", "L1:N2", values)
|
|
|
- time.sleep(1)
|
|
|
- Feishu.merge_cells("hour", "xiaoniangao", "FEcuil", "L1:N1")
|
|
|
- Common.logger("hour").info("插入今天日期成功")
|
|
|
- else:
|
|
|
- Common.logger("hour").info("今日上升榜日期已存在")
|
|
|
+ else:
|
|
|
+ # 下载封面
|
|
|
+ Common.download_method(log_type=log_type, text="cover",
|
|
|
+ d_name=str(download_video_title), d_url=str(download_cover_url))
|
|
|
+ # 下载视频
|
|
|
+ Common.download_method(log_type=log_type, text="video",
|
|
|
+ d_name=str(download_video_title), d_url=str(download_video_url))
|
|
|
+ # 保存视频信息至 "./videos/{download_video_title}/info.txt"
|
|
|
+ with open("./videos/" + download_video_title + "/" + "info.txt",
|
|
|
+ "a", encoding="UTF-8") as f_a:
|
|
|
+ f_a.write(str(int(time.time())) + "\n" +
|
|
|
+ str(download_video_title) + "\n" +
|
|
|
+ '120' + "\n" +
|
|
|
+ str(download_video_play_cnt) + "\n" +
|
|
|
+ '0' + "\n" +
|
|
|
+ '120' + "\n" +
|
|
|
+ '120' + "\n" +
|
|
|
+ str(download_video_resolution) + "\n" +
|
|
|
+ str(int(time.time())) + "\n" +
|
|
|
+ str(download_user_name) + "\n" +
|
|
|
+ str(download_head_url) + "\n" +
|
|
|
+ str(download_video_url) + "\n" +
|
|
|
+ str(download_cover_url) + "\n" +
|
|
|
+ "xiaoniangao"+str(int(time.time())))
|
|
|
+ Common.logger(log_type).info("==========视频信息已保存至info.txt==========")
|
|
|
+
|
|
|
+ # 上传视频
|
|
|
+ Common.logger(log_type).info("开始上传视频:{}".format(download_video_title))
|
|
|
+ our_video_id = Publish.upload_and_publish(log_type, env, "play")
|
|
|
+ our_video_link = "https://testadmin.piaoquantv.com/cms/post-detail/" + str(our_video_id) + "/info"
|
|
|
+ Common.logger(log_type).info("视频上传完成:{}", download_video_title)
|
|
|
+
|
|
|
+ # 保存视频: 播放量_已下载表
|
|
|
+ Common.logger(log_type).info("保存视频ID至云文档:{}", download_video_title)
|
|
|
+ # 视频ID工作表,插入首行
|
|
|
+ Feishu.insert_columns(log_type, "xiaoniangao", "67U1WF", "ROWS", 1, 2)
|
|
|
+ # 视频ID工作表,首行写入数据
|
|
|
+ upload_time = int(time.time())
|
|
|
+ values = [[
|
|
|
+ str(download_video_title),
|
|
|
+ our_video_link,
|
|
|
+ download_video_play_cnt,
|
|
|
+ str(download_video_resolution),
|
|
|
+ str(download_user_name),
|
|
|
+ str(download_user_id),
|
|
|
+ str(download_user_mid),
|
|
|
+ str(download_cover_url),
|
|
|
+ str(download_video_url)]]
|
|
|
+ time.sleep(1)
|
|
|
+ Feishu.update_values(log_type, "xiaoniangao", "67U1WF", "F2:Z2", values)
|
|
|
+
|
|
|
+ # 删除行或列,可选 ROWS、COLUMNS
|
|
|
+ Feishu.dimension_range(log_type, "xiaoniangao", "CtXmf8", "ROWS", i + 1, i + 1)
|
|
|
+ Common.logger(log_type).info("视频:{},下载/上传成功\n", download_video_title)
|
|
|
+ return
|
|
|
+
|
|
|
+ # except Exception as e:
|
|
|
+ # Common.logger(log_type).error('download_publish异常:{}', e)
|
|
|
|
|
|
- # 获取列表
|
|
|
@classmethod
|
|
|
- def get_recommend(cls, uid, token):
|
|
|
- """
|
|
|
- 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": "1c403a4aa72e3c",
|
|
|
- "X-Token-Id": "ab619e96d801f1567388629260aa68ec-1202200806",
|
|
|
- "uid": 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": "https://servicewechat.com/wxd7911e4c177690e4/624/page-frame.html"
|
|
|
- }
|
|
|
- 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": token,
|
|
|
- "uid": 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("demo").warning("获取视频feeds错误:{}", r.text)
|
|
|
- elif "list" not in r.json()["data"]:
|
|
|
- Common.logger("demo").warning("获取视频feeds无数据,休眠10s:{}", r.text)
|
|
|
+ def run_download_publish(cls, log_type, env):
|
|
|
+ # try:
|
|
|
+ while True:
|
|
|
+ if len(Feishu.get_values_batch(log_type, 'xiaoniangao', 'CtXmf8')) == 1:
|
|
|
+ Common.logger(log_type).info('上传/下载完成\n')
|
|
|
+ break
|
|
|
else:
|
|
|
- # 视频列表数据
|
|
|
- feeds = r.json()["data"]["list"]
|
|
|
- for i in range(len(feeds)):
|
|
|
- # 标题
|
|
|
- if "title" in feeds[i]:
|
|
|
- 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(" ", "")
|
|
|
- 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
|
|
|
+ cls.download_publish(log_type, env)
|
|
|
|
|
|
- # # 评论量
|
|
|
- # if "comment_count" in feeds[i]:
|
|
|
- # video_comment_cnt = feeds[i]["comment_count"]
|
|
|
- # else:
|
|
|
- # video_comment_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("demo").info("标题:{}", video_title)
|
|
|
- Common.logger("demo").info("视频ID:{}", video_id)
|
|
|
- Common.logger("demo").info("播放量:{}", video_play_cnt)
|
|
|
- # Common.logger("demo").info("点赞量:{}", video_like_cnt)
|
|
|
- # Common.logger("demo").info("分享量:{}", video_share_cnt)
|
|
|
- # Common.logger("demo").info("评论数:{}", video_comment_cnt)
|
|
|
- Common.logger("demo").info("时长:{}秒", video_duration)
|
|
|
- # Common.logger("demo").info("宽高:{}*{}", video_width, video_height)
|
|
|
- Common.logger("demo").info(
|
|
|
- "视频发布时间:{}", time.strftime(
|
|
|
- "%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time) / 1000)))
|
|
|
- Common.logger("demo").info("用户名:{}", user_name)
|
|
|
- # Common.logger("demo").info("用户头像:{}", head_url)
|
|
|
- # Common.logger("demo").info("封面:{}", cover_url)
|
|
|
- Common.logger("demo").info("播放地址:{}", video_url)
|
|
|
- except Exception as e:
|
|
|
- Common.logger("demo").error("get_recommend异常:{}", e)
|
|
|
-
|
|
|
- # 生成 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]])
|
|
|
+ # except Exception as e:
|
|
|
+ # Common.logger(log_type).error('run_download_publish异常:{}', e)
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
- # 已下载表中: P_ID
|
|
|
- user_id = '45034645'
|
|
|
- # 已下载表中: P_mid
|
|
|
- user_mid = '1160417253'
|
|
|
- # 已下载表中: 站外视频 ID
|
|
|
- video_id = '4532791008'
|
|
|
- Demo.video_detail_info(user_id, user_mid, video_id)
|
|
|
-
|
|
|
+ Demo.run_download_publish('test', 'dev')
|
|
|
pass
|