123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- # import json
- # import random
- # import time
- #
- # import requests
- #
- #
- """需兼容"""
- # class SPH:
- #
- # @classmethod
- # def find_target_user(cls, name, user_list):
- # """
- # 在搜索到到账号列表中找目标列表
- # """
- # for obj in user_list:
- # if obj['contact']["nickname"] == name:
- # return obj
- # else:
- # continue
- # return False
- #
- # @classmethod
- # def get_account_id(cls, account_name):
- # channel = 'shipinhao'
- # history_id = sqlCollect.get_history_id(channel, account_name)
- # if history_id:
- # return history_id
- # else:
- # url = "http://8.217.192.46:8889/crawler/wei_xin/shi_pin_hao/account_info"
- # payload = json.dumps({
- # "account_name": account_name
- # })
- # headers = {
- # 'Content-Type': 'application/json'
- # }
- #
- # response = requests.request("POST", url, headers=headers, data=payload)
- # response = response.json()
- # if response['code'] == 0:
- # data = response['data']['data']
- #
- # channel_account_id = data['channel_account_id']
- # if channel_account_id:
- # sqlCollect.insert_history_id(account_name, channel_account_id, channel)
- #
- #
- # return channel_account_id
- # else:
- # return False
- # else:
- # Feishu.finish_bot("shi_pin_hao/account_info接口获取失败",
- # "https://open.feishu.cn/open-apis/bot/v2/hook/575ca6a1-84b4-4a2f-983b-1d178e7b16eb",
- # "【视频号接口异常提示 】")
- # return False
- #
- # @classmethod
- # def get_sph_url(cls, task_mark, url_id, number, mark, channel_id, name):
- # account_id = cls.get_account_id(url_id)
- # if account_id:
- # url = "http://8.217.192.46:8889/crawler/wei_xin/shi_pin_hao/blogger"
- # next_cursor = ""
- # list = []
- # # for i in range(10):
- # headers = {
- # 'Content-Type': 'application/json'
- # }
- # payload = json.dumps({
- # "account_id": account_id,
- # "cursor": next_cursor
- # })
- # try:
- # response = requests.request("POST", url, headers=headers, data=payload, timeout=30)
- # time.sleep(random.randint(1, 5))
- # res_json = response.json()
- # if res_json['code'] == 0:
- # # next_cursor = res_json['data']['next_cursor']
- # data_lsit = res_json['data']['data']
- # if data_lsit == None:
- # return list
- # for obj in data_lsit:
- # objectId = obj['id']
- # day_count = Material.get_count_restrict(channel_id)
- # if day_count:
- # status = sqlCollect.is_used_days(objectId, mark, "视频号", day_count)
- # else:
- # status = sqlCollect.is_used( objectId, mark, "视频号")
- #
- # old_title = obj['objectDesc']['description']
- # url_p = obj['objectDesc']['media'][0]['Url']
- # url_token = obj['objectDesc']['media'][0]['urlToken']
- # video_url = f"{url_p}{url_token}"
- # decode_key = obj['objectDesc']['media'][0]['decodeKey']
- # cover = obj['objectDesc']['media'][0]['coverUrl']
- #
- # share_cnt = int(obj['forwardCount']) # 分享
- # like_cnt = int(obj['likeCount']) # 点赞
- # duration = int(obj['objectDesc']['media'][0]['VideoPlayLen'])
- # # duration = int(duration_ms) / 1000
- #
- # log_data = f"user:{url_id},,video_id:{objectId},,video_url:{video_url},,original_title:{old_title},,share_count:{share_cnt},,like_count:{like_cnt},,duration:{duration}"
- # AliyunLogger.logging(channel_id, name, url_id, objectId, "扫描到一条视频", "2001", log_data)
- # if status:
- # AliyunLogger.logging(channel_id, name, url_id, objectId, "该视频已改造过", "2002", log_data)
- # continue
- # video_percent = '%.2f' % (share_cnt / like_cnt)
- # special = float(0.25)
- # if like_cnt >= 30000 or like_cnt >= 50000 or (share_cnt >= 300 and float(video_percent) >= special):
- # if int(duration) < 30 or int(duration) > 720:
- # AliyunLogger.logging(channel_id, name, url, objectId, "不符合规则:时长不符合规则大于720秒/小于30秒",
- # "2003", log_data)
- #
- # continue
- # all_data = {"video_id": objectId, "cover": cover, "video_url": video_url, "rule": video_percent, "old_title": old_title, "decode_key": decode_key}
- # list.append(all_data)
- # AliyunLogger.logging(channel_id, name, url_id, objectId, "符合规则等待改造", "2004", log_data)
- # if len(list) == int(number):
- # return list
- # else:
- # AliyunLogger.logging(channel_id, name, url_id, objectId, "不符合规则:点赞小于30000/50000 或 分享/点赞小于0.25和分享小于300", "2003", log_data)
- # continue
- # return list
- # except Exception as e:
- # print(e)
- # return list
- #
- #
- # if __name__ == '__main__':
- # SPH.get_sph_url('1',"人民日报",'10','2',"视频号",'视频号品类账号')
|