import requests import time from libs.proxy import Proxy from log.print_log import PrintLog from libs.en0414 import DouYinApi class DyLiveRewardInfo: @staticmethod def get_data(room_id, retry=0): while True: if retry > 10: break retry += 1 proxy = Proxy.get() proxies = { "http": "http://" + proxy, "https": "http://" + proxy } try: dou_api = DouYinApi('', proxies) result = dou_api.register_device() device_id, iid, udid, openudid, cookie = result['device_id'], result['iid'], result['uuid'], result[ 'openudid'], result['cookie'] dou_api.init_device_ids(device_id, iid, udid, openudid) params = { "has_market": "0", "is_activated": '0' } dou_api.comm_get('https://aweme.snssdk.com/service/2/app_alert/?', params) response_json = dou_api.get_webcast_ranklist(room_id) if (response_json is not None) and (response_json.get('status_code') == 0): print('成功:' + room_id) PrintLog.print('成功:' + room_id) return response_json if retry >= 10: print('失败:' + room_id + '***') PrintLog.print('失败:' + '***') return None retry += 1 return DyLiveRewardInfo.get_data(room_id, retry) except requests.exceptions.ProxyError as e: PrintLog.print( time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '代理过期!' + str(e) + '\n' + room_id + '\n' + Proxy.proxy_info ) Proxy.del_proxy(proxy) pass except requests.exceptions.ConnectTimeout as e: PrintLog.print( time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + ' ConnectTimeout!' + str(e) + '\n' + room_id + '\n' + Proxy.proxy_info ) Proxy.del_proxy(proxy) pass except Exception as e: PrintLog.print( time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) + '请求抛出异常!' + str(e) + '\n' + room_id ) pass if __name__ == "__main__": room_id = '6955048598123891496' commodity_detail = DyLiveRewardInfo.get_data(room_id)