123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- # -*- coding: utf-8 -*-
- # @Author: wangkun
- # @Time: 2022/5/16
- import datetime
- import time
- from datetime import timedelta
- import requests
- import urllib3
- from main.common import Common
- from main.feishu_lib import Feishu
- proxies = {"http": None, "https": None}
- class Demo:
- # 查询视频详情的各项数据
- @classmethod
- def video_detail_info(cls, user_id, user_mid, video_id):
- url = "https://kapi.xiaoniangao.cn/profile/get_profile_by_id"
- headers = {
- "x-b3-traceid": "bd267349bf41b",
- "X-Token-Id": "86f6d7cc2b2b6870004df5d16c82aaf3-1185665701",
- "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
- "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/617/page-frame.html"
- }
- data = {
- "play_src": "1",
- "profile_id": int(user_id),
- "profile_mid": int(user_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": video_id,
- "hot_l1_comment": True,
- "token": "90747742180aeb22c0fe3a3c6a38f3d9",
- "uid": "8fde3c6c-c070-4379-bfc4-15c7e85139c9",
- "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)
- video_title = r.json()["data"]["title"]
- video_id = r.json()["data"]["vid"]
- video_play_cnt = r.json()["data"]["play_pv"]
- video_duration = int(r.json()["data"]["du"])/1000
- video_url = r.json()["data"]["v_url"]
- video_send_time = r.json()["data"]["t"]
- print(r.text)
- print(f"video_title:{video_title}")
- print(f"video_id:{video_id}")
- print(f"video_play_cnt:{video_play_cnt}")
- print(f"video_duration:{video_duration}")
- print(f'video_send_time:{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_send_time)/1000))}')
- print(f"video_url:{video_url}")
- except Exception as e:
- print(e)
- # 时间
- @classmethod
- def times(cls):
- # before_yesterday = (datetime.date.today() + timedelta(days=-2)).strftime("%Y/%m/%d %H:%M:%S")
- # before_yesterday = time.strptime(before_yesterday, "%Y/%m/%d %H:%M:%S")
- # before_yesterday = int(time.mktime(before_yesterday))
- # print(before_yesterday)
- # print(type(before_yesterday))
- # v_upload_time = Feishu.get_values_batch("hour", "xiaoniangao", "ba0da4")[7][5]
- # v_send_time = int(time.mktime(time.strptime(v_upload_time, "%Y-%m-%d %H:%M:%S")))
- # print(v_upload_time)
- # print(int(time.time()) - v_send_time)
- pass
- # 微信号
- @classmethod
- def get_sheet(cls):
- hour_sheet = Feishu.get_values_batch("hour", "xiaoniangao", "FEcuil")
- print(hour_sheet)
- print(hour_sheet[7][7])
- @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("今日上升榜日期已存在")
- if __name__ == "__main__":
- demo = Demo()
- # demo.video_detail_info("44838076", "116311065", "3941884615")
- # print("\n")
- # demo.video_detail_info("44767103", "116311065", "4167630382")
- # print("\n")
- # demo.video_detail_info("44264441", "329676836", "4505318929")
- # demo.times()
- # demo.video_detail_info("44615236", "460972177", "62a9965e000001609aa588ad")
- # demo.get_sheet()
- demo.check_date()
|