def get_matches_fonbet(proxy, time_out, place='live'): global url_fonbet global UA if place == 'top:live': url = url_fonbet_top_matchs.format('live') elif place == 'top:pre': url = url_fonbet_top_matchs.format('line') elif place == 'pre': url = url_fonbet_pre_matchs else: url = url_fonbet_matchs try: proxies = {'http': proxy} # prnts('Fonbet set proxy: ' + proxy, 'hide') except Exception as e: err_str = 'Fonbet error set proxy: ' + str(e) prnts(err_str) raise ValueError(err_str) try: resp = requests.get( url, headers={'User-Agent': UA}, timeout=time_out, verify=False, proxies=proxies, ) try: res = resp.json() except Exception as e: err_str = 'Fonbet error : ' + str(e) prnts(err_str) raise ValueError('Exception: ' + str(e)) if res.get("result") != "error": return res, resp.elapsed.total_seconds() else: raise ValueError(res.get("errorMessage")) except requests.exceptions.ConnectionError as e: err_str = 'Фонбет, код ошибки 0: ' + str(e) prnts(err_str) proxies = del_proxy(proxy, proxies) raise ValueError(err_str) except requests.exceptions.RequestException as e: err_str = 'Фонбет, код ошибки 1: ' + str(e) prnts(err_str) proxies = del_proxy(proxy, proxies) raise ValueError(err_str) except Exception as e: err_str = 'Фонбет, код ошибки 2: ' + str(e) prnts(err_str) # proxi_list = del_proxy(proxy, proxies) raise ValueError(err_str)
def get_matches_olimp(proxy, time_out, place, sport_id=None, time=6, liga_id=None): global olimp_data global olimp_head try: http_type = 'https' if 'https' in proxy else 'http' url = olimp_url_https if 'https' in proxy else olimp_url proxies = {http_type: proxy} # prnts('Olimp set proxy: ' + proxy, 'hide') except Exception as e: err_str = 'Olimp error set proxy: ' + str(e) prnts(err_str) raise ValueError(err_str) olimp_data_ll = olimp_data.copy() v_url = '' if place == 'live': v_url = url + '/api/slice/' else: v_url = url + '/api/' + place + '/' olimp_data_ll.update({'live': 0}) olimp_data_ll.update({'sport_id': sport_id}) if place == 'matches': olimp_data_ll.update({'id': liga_id}) else: olimp_data_ll.pop('time_shift', None) # olimp_data_ll['time'] = max(time, 6) # in app avalible 6 min hours olimp_data_ll.update({'lang_id': 2}) olimp_head_ll = olimp_head olimp_head_ll.update(olimp_get_xtoken(olimp_data_ll, olimp_secret_key)) olimp_head_ll.pop('Accept-Language', None) # print(v_url, olimp_data_ll, proxies) try: resp = requests.post( v_url, data=olimp_data_ll, headers=olimp_head_ll, timeout=time_out, verify=False, proxies=proxies, ) try: res = resp.json() except Exception as e: err_str = 'Olimp error : ' + str(e) prnts(err_str) raise ValueError('Exception: ' + str(e)) if res.get("error").get('err_code', 999) in (0, 511, 423): return res.get('data'), resp.elapsed.total_seconds() else: err_str = res.get("error") err_str = 'Olimp error : ' + str(err_str) prnts(err_str) raise ValueError(str(err_str)) except requests.exceptions.Timeout as e: err_str = 'Олимп, код ошибки Timeout: ' + str(e) prnts(err_str) proxies = del_proxy(proxy, proxies) raise TimeOut(err_str) except requests.exceptions.ConnectionError as e: err_str = 'Олимп, код ошибки ConnectionError: ' + str(e) prnts(err_str) proxies = del_proxy(proxy, proxies) raise ValueError(err_str) except requests.exceptions.RequestException as e: err_str = 'Олимп, код ошибки RequestException: ' + str(e) prnts(err_str) proxies = del_proxy(proxy, proxies) raise ValueError(err_str) except ValueError as e: if resp.text: text = resp.text err_str = 'Олимп, код ошибки ValueError: ' + str(e) + str(text) prnts(err_str) proxi_list = del_proxy(proxy, proxies) raise ValueError(err_str) except Exception as e: err_str = 'Олимп, код ошибки Exception: ' + str(e) prnts(err_str) proxies = del_proxy(proxy, proxies) raise ValueError(err_str)
def get_match_olimp(match_id, proxi_list, proxy, time_out, pair_mathes, place): global olimp_url global olimp_url_https global olimp_data match_exists = False for pair_match in pair_mathes: if match_id in pair_match: match_exists = True sport_id = if_exists(sport_list, 'name', pair_match[2], 'olimp') if match_exists is False: err_str = 'Олимп: матч ' + str( match_id ) + ' не найден в спике активных, поток get_match_olimp завершен.' prnts(err_str) raise OlimpMatchСompleted(err_str) olimp_data_m = olimp_data.copy() olimp_data_m.update({'id': match_id}) olimp_data_m.update({'lang_id': 0}) olimp_data_m.update({'sport_id': sport_id}) if place == 'pre': olimp_data_m.update({'live': 0}) olimp_stake_head = olimp_head.copy() token = get_xtoken(olimp_data_m, olimp_secret_key) olimp_stake_head.update(token) olimp_stake_head.pop('Accept-Language', None) try: http_type = 'https' if 'https' in proxy else 'http' url = olimp_url_https if 'https' in proxy else olimp_url proxies = {http_type: proxy} except Exception as e: err_str = 'Olimp error set proxy by ' + str(match_id) + ': ' + str(e) prnts(err_str) raise ValueError(err_str) resp = None try: resp = requests.post(url + '/api/stakes/', data=olimp_data_m, headers=olimp_stake_head, timeout=time_out, verify=False, proxies=proxies) try: if resp.status_code in (200, 404): res = resp.json() if res.get( 'error', {}).get('err_code') == 404 or resp.status_code == 404: # {"error": {"err_code": 404, "err_desc": "Прием ставок приостановлен"}, "data": null} raise OlimpMatchСompleted('Олимп, матч ' + str(match_id) + ' завершен, поток выключен!') else: err_str = 'Олимп ' + str( match_id) + ', get bad status_code: ' + str( resp.status_code) raise ValueError(err_str) except OlimpMatchСompleted as e: raise OlimpMatchСompleted(str(e)) except Exception as e: if resp: text = 'status_code: ' + str( resp.status_code) + ', text: ' + str(resp.text) else: text = 'resp is None, status_code: ' + str(resp.status_code) exc_type, exc_value, exc_traceback = sys.exc_info() err_str = 'Олимп ' + str(match_id) + ': ' + str( str( repr( traceback.format_exception( exc_type, exc_value, exc_traceback)))) + ', text: ' + str(text) raise ValueError(err_str) # {"error": {"err_code": 511, "err_desc": "Sign access denied"}, "data": null} # {'err_code': 423, 'err_desc': 'Переменная: id запрещена в данном методе!'} if res.get("error").get('err_code', 999) in (0, 511, 423): # 404, return resp, resp.elapsed.total_seconds() else: err = 'Олимп ' + str(match_id) + res.get("error") prnts(str(err)) raise ValueError(str(err.get('err_code'))) except OlimpMatchСompleted as e: raise OlimpMatchСompleted('Олимп, матч ' + str(match_id) + ' завершен, поток выключен!') except requests.exceptions.Timeout as e: err_str = 'Олимп ' + str(match_id) + ', код ошибки Timeout: ' + str(e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise TimeOut(err_str) except requests.exceptions.ConnectionError as e: err_str = 'Олимп ' + str( match_id) + ', код ошибки ConnectionError: ' + str(e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str) except requests.exceptions.RequestException as e: err_str = 'Олимп ' + str( match_id) + ', код ошибки RequestException: ' + str(e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str) except ValueError as e: err_str = 'Олимп ' + str(match_id) + ', код ошибки ValueError: ' + str( e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str) except Exception as e: # if str(e) == '404': # prnts(e) # raise OlimpMatchСompleted('Олимп, матч ' + str(match_id) + ' завершен, поток выключен!') err_str = 'Олимп ' + str(match_id) + ', код ошибки Exception: ' + str( e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str)
def get_matches(bk_name, proxy, timeout, api_key, x_session, x_device_uuid, proxy_list, session, place): if bk_name == 'pinnacle': head = list_matches_head if api_key: head.update({'x-api-key': api_key}) if x_device_uuid: head.update({'x-device-uuid': x_device_uuid}) if x_session: head.update({'x-session': x_session}) if 'live' == place: url = url_live else: url = url_pre proxies = {'https': proxy} data = {} resp = {} for sport in utils.sport_list: sport_id = sport.get('pinnacle') sport_name = sport.get('name') if utils.if_exists_by_sport(utils.sport_list, bk_name, sport_id, 'place', place): if sport_id: try: if session: sx = session.get else: sx = requests.get # utils.prnts('session get_matches: ' + str(session)) resp = sx( url.format(sport_id), headers=head, timeout=timeout, verify=False, proxies=proxies, ) try: res = resp.json() check_data(res, sport_id, place, api_key) # {'detail': 'The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.', 'status': 404, 'title': 'Not Found', 'type': 'about:blank'} # print(json.dumps(res)) # print('---') res_status = 200 if type(res) != list: res_status = res.get('status', 404) if res_status != 200: err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error, res_status: ' + str(res_status) + ', res: ' + str(res.text) utils.prnts(err_str) pass else: for l in filter( lambda x: ( x.get('league', {}).get('sport', {}).get('name', '') != 'Hockey' and x.get('liveMode', '') == 'live_delay' and x.get('units', '') == 'Regular' # разкомментить для удаления угловых and (x.get('parent') if x.get('parent') else {}).get('participants', [{}])[0].get('name', '') == x.get('participants', [{}])[0].get('name', '') # закомментить для добавления сетов и геймов ) or (x.get('league', {}).get('sport', {}).get('name', '') == 'Hockey'), res): if str(l.get('id')) in '1102576922': print(json.dumps(l)) # if place == 'pre': # print(l) # {'ageLimit': 0, 'altTeaser': False, 'external': {}, 'hasLive': True, 'hasMarkets': True, 'id': 1094249412, 'isHighlighted': False, 'isLive': True, 'isPromoted': False, # 'league': {'ageLimit': 0, 'external': {}, 'featureOrder': -1, 'group': 'World', 'id': 1863, 'isFeatured': False, 'isHidden': False, 'isPromoted': False, 'isSticky': False, # 'matchupCount': 3, 'name': 'Club Friendlies', 'sport': {'featureOrder': 0, 'id': 29, 'isFeatured': True, 'isHidden': False, 'isSticky': False, 'matchupCount': 532, # 'name': 'Soccer', 'primaryMarketType': 'moneyline'}}, 'liveMode': 'live_delay', 'parent': {'id': 1094249362, 'participants': [{'alignment': 'home', 'name': 'Club Sport Emelec', 'score': None}, # {'alignment': 'away', 'name': 'LDU de Portoviejo', 'score': None}], 'startTime': '2020-01-31T01:30:00+00:00'}, 'parentId': 1094249362, 'parlayRestriction': 'unique_matchups', 'participants': # [{'alignment': 'home', 'name': 'Club Sport Emelec', 'order': 0, 'state': {'score': 2}}, {'alignment': 'away', 'name': 'LDU de Portoviejo', 'order': 1, 'state': {'score': 0}}], # 'periods': [{'cutoffAt': '2020-01-31T04:14:42Z', 'period': 0, 'status': 'open'}, {'cutoffAt': None, 'period': 1, 'status': 'settled'}], 'rotation': 1301, 'startTime': '2020-01-31T01:30:00Z', # 'state': {'minutes': 39, 'state': 3}, 'status': 'started', 'totalMarketCount': 2, 'type': 'matchup', 'units': 'Regular', 'version': 256440882} participants = l.get('participants', [{}]) participant_0 = participants[0] participant_1 = participants[1] # TODO witout home/ away # [{'alignment': 'neutral', 'id': 1103553309, 'name': 'Over', 'order': 0, 'rotation': 16}, {'alignment': 'neutral', 'id': 1103553310, 'name': 'Under', 'order': 0, 'rotation': 17}] if participant_0.get('alignment') in ('home', 'away'): if participant_0.get('alignment') == 'home': team1 = participant_0.get('name') team2 = participant_1.get('name') score1 = participant_0.get('state', {}).get('score', participant_0.get('score', '')) score2 = participant_1.get('state', {}).get('score', participant_1.get('score', '')) elif participant_0.get('alignment') == 'away': team2 = participant_0.get('name') team1 = participant_1.get('name') score2 = participant_0.get('state', {}).get('score', participant_0.get('score', '')) score1 = participant_1.get('state', {}).get('score', participant_1.get('score', '')) data[l.get('id')] = { 'time_req': round(time.time()), 'place': place, 'bk_name': bk_name, 'match_id': l.get('id'), 'league': l.get('league', {}).get('group') + '-' + l.get('league', {}).get('name'), 'team1': team1, 'team2': team2, 'name': team1 + '-' + team2, 'score': str(score1) + ':' + str(score2), 'state': l.get('state', {}).get('state'), 'minute': float(l.get('state', {}).get('minutes', 0)), 'sport_id': sport_id, 'sport_name': sport_name, 'start_time': int(datetime.datetime.strptime(l.get('startTime'), '%Y-%m-%dT%H:%M:%SZ').timestamp()), 'units': l.get('units'), 'liveMode': l.get('liveMode') } except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error: ' + str(repr(traceback.format_exception(exc_type, exc_value, exc_traceback))) if resp: err_str + '\ndata:' + resp.text utils.prnts(err_str) raise ValueError('Exception: ' + str(e)) if resp.status_code != 200: err_str = res.get("error") err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error : ' + str(err_str) utils.prnts(err_str) raise ValueError(str(err_str)) except requests.exceptions.Timeout as e: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error: ' + str(repr(traceback.format_exception(exc_type, exc_value, exc_traceback))) utils.prnts(err_str) proxies = proxy_worker.del_proxy(proxy, proxy_list) raise exceptions.TimeOut(err_str) except requests.exceptions.ConnectionError as e: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error: ' + str(repr(traceback.format_exception(exc_type, exc_value, exc_traceback))) utils.prnts(err_str) proxies = proxy_worker.del_proxy(proxy, proxy_list) raise ValueError(err_str) except requests.exceptions.RequestException as e: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error: ' + str(repr(traceback.format_exception(exc_type, exc_value, exc_traceback))) utils.prnts(err_str) proxies = proxy_worker.del_proxy(proxy, proxy_list) raise ValueError(err_str) except ValueError as e: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error1: ' + str(repr(traceback.format_exception(exc_type, exc_value, exc_traceback))) utils.prnts(err_str) proxi_list = proxy_worker.del_proxy(proxy, proxy_list) raise ValueError(err_str) except Exception as e: exc_type, exc_value, exc_traceback = sys.exc_info() err_str = bk_name + ' ' + url.format(sport_id) + ' ' + 'error: ' + str(repr(traceback.format_exception(exc_type, exc_value, exc_traceback))) utils.prnts(err_str) proxies = proxy_worker.del_proxy(proxy, proxy_list) raise ValueError(err_str) return data, resp.elapsed.total_seconds() if not data: return {}, 0
def get_match_fonbet(match_id, proxi_list, proxy, time_out, pair_mathes): global url_fonbet_match global fonbet_header match_exists = False for pair_match in pair_mathes: if match_id in pair_match: match_exists = True if match_exists is False: err_str = 'Фонбет: матч ' + str( match_id ) + ' не найден в спике активных, поток get_match_fonbet завершен.' raise FonbetMatchСompleted(err_str) try: proxies = {'http': proxy} except Exception as e: err_str = 'Fonbet error set proxy by ' + str(match_id) + ': ' + str(e) prnts(err_str) raise ValueError(err_str) try: resp = requests.get( url_fonbet_match + str(match_id) + "&lang=en", headers=fonbet_header, timeout=time_out, verify=False, proxies=proxies, ) try: res = resp.json() # print_j(res) except Exception as e: err_str = 'Fonbet error by ' + str(match_id) + ': ' + str(e) prnts(err_str) raise ValueError(err_str) if res.get("result") != "error": return res, resp.elapsed.total_seconds() elif res.get("place", "live") == "notActive": raise FonbetMatchСompleted('0 Фонбет, матч ' + str(match_id) + ' завершен, поток выключен!') else: if 'Event not found' in res.get("errorMessage"): raise FonbetMatchСompleted('1 Фонбет, матч ' + str(match_id) + ' завершен, поток выключен!') err = res.get("errorMessage") prnts(str(err)) raise ValueError(str(err)) except requests.exceptions.ConnectionError as e: err_str = 'Фонбет ' + str(match_id) + ', код ошибки 0: ' + str(e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str) except requests.exceptions.RequestException as e: err_str = 'Фонбет ' + str(match_id) + ', код ошибки 1: ' + str(e) prnts(err_str) proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str) except FonbetMatchСompleted as e: raise FonbetMatchСompleted('2 ' + str(e)) except Exception as e: if 'Event not found' in str(e): raise FonbetMatchСompleted('3 Фонбет, матч ' + str(match_id) + ' завершен, поток выключен! ' + str(e)) err_str = 'Фонбет ' + str(match_id) + ', код ошибки 2: ' + str(e) prnts(err_str) # proxi_list = del_proxy(proxy, proxi_list) raise ValueError(err_str)