123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import random
- import time
- import requests
- import json
- import re
- from common import Material, Feishu, Common
- from common.sql_help import sqlCollect
- class SphNrxs:
- @classmethod
- def get_sph_data(cls, user, nick_name, uid):
- url = "http://61.48.133.26:30001/FinderGetUpMasterNextPage"
- count = 1
- headers = {
- 'Content-Type': 'application/json'
- }
- payload = json.dumps({
- "username": user,
- "last_buffer": ""
- })
- response = requests.request("POST", url, headers=headers, data=payload)
- time.sleep(random.randint(1, 5))
- Common.logger("sph_nrxs").info(f"{user}获取第{count}页视频")
- count += 1
- if response.text == "" or response.text == None:
- return
- res_json = response.json()
- try:
- if len(res_json["DownloadAddress"]) == 0 or res_json["DownloadAddress"] == "" or res_json[
- "DownloadAddress"] == None:
- return
- except:
- pass
- if "objectId" not in response.text or response.status_code != 200:
- return
- if len(res_json["UpMasterHomePage"]) == 0:
- return
- if not res_json["UpMasterHomePage"]:
- return
- try:
- for obj in res_json["UpMasterHomePage"]:
- Common.logger("sph_crawling").info(f"{user}扫描到一条数据")
- objectId = obj['objectId']
- object_id = sqlCollect.sph_data_info_v_id(objectId, "视频号")
- if object_id:
- continue
- objectNonceId = obj['objectNonceId']
- url1 = "http://61.48.133.26:30001/GetFinderDownloadAddress"
- payload = json.dumps({
- "objectId": objectId,
- "objectNonceId": objectNonceId
- })
- headers = {
- 'Content-Type': 'text/plain'
- }
- response = requests.request("POST", url1, headers=headers, data=payload)
- time.sleep(random.randint(0, 1))
- video_obj = response.json()
- video_url = video_obj.get('DownloadAddress')
- if len(video_url) == 0:
- continue
- duration = video_obj.get('play_len')
- # cover = video_obj.get('thumb_url')
- share_cnt = int(obj['forward_count']) # 分享
- like_cnt = int(obj['like_count']) # 点赞
- # user_name = obj['username'] # 用户名标示
- nick_name = obj['nickname'] # 用户名
- # comment_count = obj['comment_count'] # 评论数
- # fav_count = obj['fav_count'] # 大拇指点赞数
- values = [
- [
- uid,
- nick_name,
- like_cnt,
- share_cnt,
- duration,
- video_url
- ]
- ]
- Feishu.insert_columns("UBvisMdE7hkI6rtIfzycCtdsnWM", '3476ab', "ROWS", 1, 2)
- time.sleep(0.5)
- Feishu.update_values("UBvisMdE7hkI6rtIfzycCtdsnWM", '3476ab', "A2:Z2", values)
- Common.logger("sph_nrxs").info(f"{nick_name}符合规则")
- except Exception as e:
- Common.logger("sph_nrxs").info(f"{user}异常,异常信息{e}")
- return
- @classmethod
- def get_nrxs_list(cls, uid):
- list = []
- cookie = Material.get_cookie_data("KsoMsyP2ghleM9tzBfmcEEXBnXg", "U1gySe", "视频号加热")
- url = "http://8.217.190.241:8888/crawler/wei_xin/shi_pin_hao/jia_re"
- payload = json.dumps({
- "account_name": uid,
- "category": "推荐",
- "cookie": cookie
- })
- headers = {
- 'Content-Type': 'application/json'
- }
- try:
- time.sleep(2)
- response = requests.request("POST", url, headers=headers, data=payload)
- response = response.json()
- code = response['code']
- if code == 0:
- data_list = response['data']['data']
- if data_list:
- for data in data_list:
- nick_name = data['nickName'] # 用户名
- user_name = data['username'] # 用户v2
- data_dict = {"nick_name": nick_name, "user_name": user_name}
- cls.get_sph_data(user_name, nick_name, uid)
- list.append(data_dict)
- return list
- else:
- Feishu.bot("xinxin", '视频号加热提醒', f'cookie 失效了,请即使更换', 'xinxin')
- return None
- except Exception as e:
- Feishu.bot("xinxin", '视频号加热提醒', f'cookie 失效了,请即使更换', 'xinxin')
- Common.logger("feishu").error(f"视频号加热bot异常:{e}\n")
- return None
- @classmethod
- def sph_nrxs_data(cls):
- user = sqlCollect.get_machine_making_reflux("视频号", "单点视频")
- if user == None:
- return
- user = [item[0] for item in user]
- for uid in user:
- if re.match(r'^[A-Za-z0-9]+$', uid):
- # 匹配成功,进行下一次循环
- continue
- list = cls.get_nrxs_list(uid)
- print(list)
- if __name__ == '__main__':
- SphNrxs.sph_nrxs_data()
|