import json import requests from common import AliyunLogger from common.sql_help import sqlCollect class KSXCX: @classmethod def get_xcx_date(cls,channel_id): list = [] try: url = "http://8.217.192.46:8889/crawler/kuai_shou/mp_recommend" payload = json.dumps({ "cursor": "" }) headers = { 'Content-Type': 'application/json' } response = requests.request("POST", url, headers=headers, data=payload) response = response.json() code = response['code'] if code == 0: data_list = response['data']['data'] for data in data_list: type = int(data['type']) if type != 1: continue photo_type = data['photoType'] if photo_type != "VIDEO": continue duration = int(int(data["duration"])/1000) cover_url = data['webpCoverUrls'][0]['url'] video_url = data['mainMvUrls'][0]['url'] like_count = data.get('likeCount', 0) timestamp = data['timestamp'] share_count = data.get('shareCount', 0) comment_count = data.get('commentCount', 0) view_count = data.get('viewCount', 0) title = data['caption'] photo_id = data['photoId'] user_name = data['share_info'] log_data = f"user:快手小程序,,video_id:{photo_id},,video_url:{video_url},original_title:{title},,share_count:{share_count},,view_count:{view_count},,duration:{duration}" AliyunLogger.logging("快手小程序", "快手小程序",user_name, photo_id, "扫描到一条视频", "2001", log_data) status = sqlCollect.ks_is_used_xcx(photo_id,"快手小程序") if status: AliyunLogger.logging("快手小程序", "快手小程序", user_name,photo_id, "该视频已改造过", "2002", log_data) continue if duration <= 30: AliyunLogger.logging("快手小程序", "快手小程序",user_name, photo_id, f"不符合规则:时长不符合规则小于30秒,视频时长{duration}", "2003", log_data) continue if int(share_count) < 1000: AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id, f"分享小于1000,实际点赞{share_count}", "2003", log_data) continue video_percent = '%.4f' % (int(share_count) / int(like_count)) if float(video_percent) < 0.15: AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id, f"分享/点赞 < 15%,实际占比{video_percent}", "2003", log_data) continue all_data = {"video_id": photo_id, "cover": cover_url, "video_url": video_url, "rule": video_percent, "old_title": title} if not list and any(item["video_id"] == all_data["video_id"] for item in list): AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id, "重复视频", "2002", log_data) continue list.append(all_data) AliyunLogger.logging("快手小程序", "快手小程序", user_name, photo_id, "符合规则等待改造", "2004", log_data) return list except Exception as e: return list if __name__ == '__main__': KSXCX.get_xcx_date()