Пример #1
0
def start_proxy_saver(proxies_olimp, proxies_fonbet, proxy_filename_olimp,
                      proxy_filename_fonbet):
    while True:
        prnts('Proxies by Olimp: ' + str(len(proxies_olimp)))  # , 'hide'
        prnts('Proxies by Fonbet: ' + str(len(proxies_fonbet)))

        save_list(proxies_olimp, proxy_filename_olimp)
        save_list(proxies_fonbet, proxy_filename_fonbet)
        time.sleep(15)
Пример #2
0
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)
Пример #3
0
def start_proxy_saver(proxies_container):
    while True:
        for bk_name in proxies_container.keys():
            prnts(
                'Proxies by ' + bk_name + ': ' +
                str(len(proxies_container.get(bk_name, {}).get('proxy_list'))))
            save_list(
                proxies_container.get(bk_name, {}).get('proxy_list'),
                proxies_container.get(bk_name, {}).get('proxy_filename'))
        time.sleep(15)
Пример #4
0
async def save(proxies, proxy_list):
    x = 0
    while True:
        proxy = await proxies.get()
        if proxy is None:
            break
        proto = 'https' if 'HTTPS' in proxy.types else 'http'
        row = '%s://%s:%d' % (proto, proxy.host, proxy.port)
        proxy_list.append(row)
        x = x + 1
        prnts(x)
Пример #5
0
def to_abb(sbet):
    sbet = sbet.replace(' ', '').replace('\t', '')
    value = re.findall('\((.*)\)', sbet)[0]
    key = re.sub('\((.*)\)', '', sbet)
    abr = ''
    try:
        abr = abbreviations[key].format(value)
    except Exception as e:
        if DEBUG:
            prnts(
                'error: ' + str(e) + ', to_abb("' + sbet + '"), value=' +
                value + ', key=' + key, 'hide')
    return abr
Пример #6
0
def check_data(data, sport_id, place, api_key):
    if type(data) == dict and data.get('status'):
        utils.prnts('data: ' + str(data))
        title_err = data.get('title')
        if title_err == 'BAD_APIKEY':
            utils.prnts('api_key: ' + str(api_key))
        elif title_err == 'AUTH_SUPERSEDED':
            utils.prnts('Session expired! TODO: relogin')
        else:
            utils.prnts('error data: ' + place + ' ' + str(sport_id) + ' ' + str(data), hide=True)
Пример #7
0
def del_proxy(proxy, shared_proxies):
    if proxy in shared_proxies:
        shared_proxies.remove(proxy)
        if DEBUG:
            prnts('del_proxy, proxy deleted: ' + str(proxy))
        else:
            prnts('del_proxy, proxy deleted: ' + str(proxy), 'hide')
        return shared_proxies
    else:
        pass
        prnts('del_proxy, proxy is not found: ' + str(proxy), 'hide')
        return shared_proxies
Пример #8
0
 def do_GET(self):
     ip_adr = ''
     try:
         ip_adr = str(self.client_address[0])
     except Exception as e:
         exc_type, exc_value, exc_traceback = sys.exc_info()
         err_str = str(
             traceback.format_exception(exc_type, exc_value,
                                        exc_traceback))
         prnts(err_str)
     if self.path == '/get_forks':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(str(self.data_str).encode('utf-8'))
     elif self.path == '/get_cnt_matches':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(str(pair_mathes + arr_cupon).encode('utf-8'))
     elif self.path == '/get_cnt_top_matches':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(
             str(arr_top_matchs.get('top', [])).encode('utf-8'))
     elif self.path == '/get_middle':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(
             str(arr_top_matchs.get('middle', [])).encode('utf-8'))
     elif self.path == '/get_slag':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(
             str(arr_top_matchs.get('slag', [])).encode('utf-8'))
     elif self.path == '/end':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(str(mathes_complite).encode('utf-8'))
     elif self.path == '/end/live':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(
             str(mathes_complite.get('live', [])).encode('utf-8'))
     elif self.path == '/end/pre':
         self.send_response(200)
         self.send_header('content-type', 'application/json')
         self.end_headers()
         self.wfile.write(
             str(mathes_complite.get('pre', [])).encode('utf-8'))
     elif '/fonbet/' in self.path or '/olimp/' in self.path or '/pinnacle/' in self.path:
         cnt_par = str(self.path).count('/')
         prnts('get path: {}, cnt_par: {}, arr: {}'.format(
             self.path, cnt_par, str(self.path.split('/'))))
         answer = 'ok'
         branch = ''
         try:
             answer = None
             if cnt_par == 2:
                 balnk, bk_name, match_id = self.path.split('/')
                 answer = get_state(bets.get(match_id, {}))
             elif cnt_par == 3:
                 balnk, bk_name, match_id, kof = self.path.split('/')
                 kof = unquote(kof)
                 answer = bets.get(match_id, {}).get('kofs',
                                                     {}).get(kof)
             if answer:
                 try:
                     answer.pop('hist')
                 except:
                     pass
                 answer = json.dumps(answer,
                                     ensure_ascii=False,
                                     indent=4)
         except Exception as e:
             exc_type, exc_value, exc_traceback = sys.exc_info()
             answer = branch + ': ' + str(
                 traceback.format_exception(exc_type, exc_value,
                                            exc_traceback))
             prnts(answer)
         finally:
             self.send_response(200)
             self.send_header('content-type', 'application/json')
             self.end_headers()
             self.wfile.write(str(answer).encode('utf-8'))
     elif '/set/' in self.path:
         prnts(self.path)
         status = 'ok'
         branch = ''
         try:
             branch = 'fonbet_maxbet_fact'
             if branch in self.path:
                 # expected format request like "/set/fonbet_maxbet_fact/4/100"
                 blank, action, param_name, key, group_id, value = self.path.split(
                     '/')
                 key = unquote(key)
                 prnts(
                     branch +
                     ': action: {}, param_name: {}, key: {}, group_id: {}, value: {}'
                     .format(action, param_name, key, group_id, value))
                 old_val = forks.get(key, {}).get(param_name,
                                                  {}).get(group_id, 0)
                 max_val = max(old_val, int(float(value)))
                 forks[key][param_name].update({str(group_id): max_val})
                 prnts(
                     branch +
                     ': group_id:{}, old_val:{}, cur_val:{}, max_val: {}'
                     .format(group_id, old_val, value, max_val))
         except Exception as e:
             exc_type, exc_value, exc_traceback = sys.exc_info()
             status = branch + ': ' + str(
                 traceback.format_exception(exc_type, exc_value,
                                            exc_traceback))
             prnts(status)
         finally:
             self.send_response(200)
             self.send_header('content-type', 'application/json')
             self.end_headers()
             self.wfile.write(str(status).encode('utf-8'))
     else:
         mutex.acquire()
         with open('access.log', 'a+', encoding='utf-8') as f:
             f.write('ip: ' + ip_adr + ', path: ' + self.path + '\n')
         mutex.release()
Пример #9
0
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)
Пример #10
0
def get_bets_olimp(bets_olimp,
                   match_id,
                   proxies_olimp,
                   proxy,
                   time_out,
                   pair_mathes,
                   place,
                   n=0):
    global sport_list
    key_id = str(match_id)

    match_exists = False
    for pair_match in pair_mathes:
        if match_id in pair_match:
            match_exists = True
            minute_complite = if_exists(sport_list, 'name', pair_match[2],
                                        'min')
            my_sport_name = pair_match[2]
    if match_exists is False:
        err_str = 'Олимп: матч ' + str(
            match_id
        ) + ' не найден в спике активных, поток get_bets_olimp завершен.'
        raise OlimpMatchСompleted(err_str)
    resp_temp = ''
    try:
        res, time_resp = get_match_olimp(match_id, proxies_olimp, proxy,
                                         time_out, pair_mathes, place)
        resp = res.json().get('data')
        if res.status_code == 404:
            # res: {"error":{"err_code":404,"err_desc":"Прием ставок приостановлен"},"data":null}, status_code: 404
            # prnts('Олимп ' + key_id + '. Получен пустой ответ при запросе матча, ставим math_block=True, time_resp: ' + str(time_resp) + ', res: ' + str(res.text) + ', status_code: ' + str(res.status_code))
            math_block = True
        math_block = False
        resp_temp = str(resp)
        time_start_proc = time.time()
        if not math_block:
            if place == 'pre':
                if resp:
                    math_block = resp.get('ms', False)
                else:
                    math_block = False
            else:
                math_block = True if not resp or str(resp.get(
                    'ms', '1')) != '2' or resp.get('error', {
                        'err_code': 0
                    }).get('err_code') == 404 else False
                # 1 - block, 2 - available
                if str(resp.get('ms', '')) == '4':
                    err_str = 'Олимп: матч, ' + my_sport_name + ' - ' + str(
                        match_id) + ' завершен, т.к. ms=4'
                    raise OlimpMatchСompleted(err_str)

        if not math_block:
            timer = resp.get('t', '')
            minute = -1  # (2:0) Перерыв
            try:
                minute = int(
                    re.findall('\d{1,2}\\"', resp.get('sc',
                                                      ''))[0].replace('"', ''))
            except:
                pass

            if minute_complite:
                if minute >= (int(minute_complite) - 2):
                    err_str = 'Олимп: матч, ' + my_sport_name + ' - ' + str(
                        match_id) + ' завершен, т.к. ' + str(
                            minute_complite - 2) + ' минут прошло.'
                    raise OlimpMatchСompleted(err_str)
            skId = resp.get('sport_id')
            skName = resp.get('sn')
            sport_name = resp.get('cn')
            champid = sport_name  # NOT FOUND
            name = resp.get('n')
            # if name == 'Ювентус - Удинезе':
            #     print('resp: ' + str(resp))
            start_time = int(resp.get('t', 0))
            start_after_min = math.floor((start_time - int(time.time())) / 60)
            if place == 'pre':
                if start_after_min:
                    if start_after_min <= 5:
                        err_str = 'Олимп: pre матч, ' + skName + ' - ' + str(
                            match_id) + ' завершен, т.к. ' + str(
                                start_after_min) + ' минут до начала матча.'
                        raise OlimpMatchСompleted(err_str)
            if not start_after_min:
                start_after_min = 0
            if start_after_min <= -120:
                err_str = 'Олимп: матч, ' + skName + ' - ' + str(
                    match_id) + ' завершен, т.к. прошло ' + str(
                        abs(start_after_min)) + ' минут от начала матча.'
                raise OlimpMatchСompleted(err_str)
            score = ''
            sc1 = 0
            sc2 = 0
            try:
                score = resp.get('sc', '0:0').split(' ')[0]
                try:
                    sc1 = int(score.split(':')[0])
                except Exception as e:
                    pass
                    # prnts('err util_olimp sc1: ' + str(e))
                try:
                    sc2 = int(score.split(':')[1])
                except Exception as e:
                    pass
                    # prnts('err util_olimp sc2: ' + str(e))
            except:
                if DEBUG:
                    prnts('err util_olimp error split: ' +
                          str(resp.get('sc', '0:0')))

            try:
                bets_olimp[key_id].update({
                    'sport_id': skId,
                    'place': place,
                    'sport_name': skName,
                    'league': sport_name,
                    'liga_id': champid,
                    'name': name,
                    'score': score,
                    'time_start': timer,
                    'start_after_min': start_after_min,
                    'start_time': start_time,
                    'time_req': round(time.time())
                })
            except:
                bets_olimp[key_id] = {
                    'bk_name': 'olimp',
                    'sport_id': skId,
                    'place': place,
                    'sport_name': skName,
                    'league': sport_name,
                    'liga_id': champid,
                    'name': name,
                    'score': score,
                    'time_start': timer,
                    'start_after_min': start_after_min,
                    'start_time': start_time,
                    'time_req': round(time.time()),
                    # 'time_change_total': round(time.time()),
                    # 'avg_change_total': [],
                    'kofs': {}
                }

            for c in resp.get('it', []):
                # del: угловые
                group_kof = c.get('n', '').replace(' ', '').lower()
                group_kof = group_kof.replace('азиатские', '')
                if group_kof in [
                        'основные', 'голы', 'инд.тотал', 'доп.тотал',
                        'исходыпотаймам', 'победасучетомфоры', 'форы',
                        'тоталы', 'инд.тоталы'
                ]:
                    for d in c.get('i', []):
                        if 'обе забьют: '.lower() \
                                in d.get('n', '').lower() \
                                or 'забьет: '.lower() \
                                in d.get('n', '').lower() \
                                or 'никто не забьет: '.lower() \
                                in d.get('n', '').lower() \
                                or 'победа '.lower() \
                                in d.get('n', '').lower() \
                                or d.get('n', '').lower().endswith(' бол') \
                                or d.get('n', '').lower().endswith(' мен') \
                                or 'с форой'.lower() \
                                in d.get('n', '').lower() \
                                or 'первая не проиграет'.lower() \
                                in d.get('n', '').lower() \
                                or 'вторая не проиграет'.lower() \
                                in d.get('n', '').lower() \
                                or 'ничьей не будет' \
                                in d.get('n', '').lower() \
                                or 'ничья'.lower() \
                                in d.get('n', '').lower() \
                                or 'форы' in group_kof:
                            c1 = str(resp.get('c1', ''))
                            c2 = str(resp.get('c2', ''))
                            if 'форы' in group_kof:
                                key_r = d.get('n', '').replace(
                                    c1, 'П1сфорой').replace(c2, 'П2сфорой')
                                key_r = key_r.replace(' ', '')
                            else:
                                key_r = d.get('n', '').replace(c1,
                                                               'Т1').replace(
                                                                   c2, 'Т2')
                            coef = str([
                                abbreviations[c.replace(' ', '')] if c.replace(
                                    ' ', '') in abbreviations.keys() else
                                c.replace(' ', '') if '(' not in c.replace(
                                    ' ', '') else to_abb(c) for c in [key_r]
                            ][0])
                            if coef:
                                value = d.get('v', 0)
                                kof_order = bets_olimp[key_id].get(
                                    'kofs',
                                    {}).get(coef, {}).get('hist',
                                                          {}).get('order', [])
                                time_change = bets_olimp[key_id].get(
                                    'kofs', {}).get(coef,
                                                    {}).get('hist', {}).get(
                                                        'time_change',
                                                        time.time())
                                avg_change = bets_olimp[key_id].get(
                                    'kofs',
                                    {}).get(coef,
                                            {}).get('hist',
                                                    {}).get('avg_change', [])

                                try:
                                    if value != kof_order[-1]:
                                        kof_order.append(value)
                                        avg_change.append(0)
                                        time_change = time.time()
                                    elif value == kof_order[-1]:
                                        avg_change[-1] = round(time.time() -
                                                               time_change)
                                except IndexError:
                                    # firs
                                    kof_order.append(value)
                                    avg_change.append(0)
                                try:
                                    bets_olimp[key_id]['kofs'].update({
                                        coef: {
                                            'time_req': round(time.time()),
                                            'value': value,
                                            'apid': d.get('apid', ''),
                                            'factor': d.get('v', 0),
                                            'sport_id': skId,
                                            'event': match_id,
                                            'vector':
                                            get_vector(coef, sc1, sc2),
                                            'hist': {
                                                'time_change': time_change,
                                                'avg_change': avg_change,
                                                'order': kof_order
                                            }
                                        }
                                    })
                                except:
                                    pass
            # if key_id == '52495128':
            #     prnts(key_id)
            #     prnts(bets_olimp)
            #     prnts(resp)
        else:
            if bets_olimp.get(key_id):
                if DEBUG:
                    prnts(
                        'Олимп матч {}, {} заблокирован:{}'.format(
                            place, key_id, math_block), 'hide')
            else:
                if DEBUG:
                    prnts(
                        'Олимп матч {}, {} заблокирован и это первое добаление:{}'
                        .format(place, key_id, math_block), 'hide')
            if bets_olimp.get(key_id):
                bets_olimp[key_id].update({'time_req': round(time.time())})
            else:
                pass
                # prnts('Олимп, не смог обновить время time_req, т.к. матч ' + str(key_id) + ' заблокирован и это первое добавление?')

            try:
                if bets_olimp.get(key_id):
                    for j in list(bets_olimp[key_id].get('kofs', {})):
                        try:
                            kof_order = bets_olimp[key_id]['kofs'][j].get(
                                'hist', {}).get('order', [])
                            time_change = bets_olimp[key_id]['kofs'][j].get(
                                'hist', {}).get('time_change', time.time())
                            avg_change = bets_olimp[key_id]['kofs'][j].get(
                                'hist', {}).get('avg_change', [])
                            try:
                                if 0 != kof_order[-1]:
                                    kof_order.append(0)
                                    # avg_change.append(round(time.time() - time_change))
                                    avg_change.append(0)
                                    time_change = time.time()
                                elif 0 == kof_order[-1]:
                                    avg_change[-1] = round(time.time() -
                                                           time_change)
                            except IndexError:
                                # firs
                                kof_order.append(0)
                                avg_change.append(0)
                            if bets_olimp.get(key_id, {}).get('kofs',
                                                              {}).get(j):
                                bets_olimp[key_id]['kofs'][j]['value'] = 0
                                bets_olimp[key_id]['kofs'][j]['factor'] = 0
                                bets_olimp[key_id]['kofs'][j][
                                    'time_req'] = round(time.time())
                                if bets_olimp[key_id]['kofs'][j].get(
                                        'hist') is None:
                                    bets_olimp[key_id]['kofs'][j]['hist'] = {}
                                bets_olimp[key_id]['kofs'][j]['hist'][
                                    'avg_change'] = avg_change
                                bets_olimp[key_id]['kofs'][j]['hist'][
                                    'time_change'] = time_change
                                bets_olimp[key_id]['kofs'][j]['hist'][
                                    'kof_order'] = kof_order
                                if kof_order[-1]:
                                    # prnts('Олимп x, матч заблокирован, знач. выставил в 0: ' + key_id + ' ' + str(j), 'hide')
                                    prnts(
                                        'Олимп x, матч заблокирован, знач. выставил в 0: '
                                        + key_id + ' ' + str(j) +
                                        'math_block: ' + str(math_block) +
                                        ' запрос №: ' + n)
                            else:
                                pass
                                # prnts('Олимп x, матч заблокирован и это первое добавлени значение не выставляю в 0: ' + key_id + ' ' + str(j), 'hide')
                                prnts(
                                    'Олимп x, матч заблокирован и это первое добавлени: '
                                    + key_id + ' ' + str(j) + ' math_block: ' +
                                    str(math_block) + ' запрос №: ' + n)
                        except Exception as e:
                            exc_type, exc_value, exc_traceback = sys.exc_info()
                            err_str = 'error: ' + str(e) + ' (' + str(
                                repr(
                                    traceback.format_exception(
                                        exc_type, exc_value,
                                        exc_traceback))) + ')'
                            prnts(
                                'Олимп x, матч:' + key_id +
                                ' ошибка 00 при удалении старой котирофки: ' +
                                str(err_str) + ' math_block: ' +
                                str(math_block) + ' запрос №: ' + n)
                            time.sleep(5)
            except Exception as e:
                exc_type, exc_value, exc_traceback = sys.exc_info()
                err_str = 'error: ' + str(e) + ' (' + str(
                    repr(
                        traceback.format_exception(exc_type, exc_value,
                                                   exc_traceback))) + ')'
                prnts('Олимп x, матч:' + key_id +
                      ' ошибка 0 при удалении установке в 0 котирофки: ' +
                      str(err_str) + ' math_block: ' + str(math_block) +
                      ' запрос №: ' + n)
                time.sleep(5)
            return time_resp + (time.time() - time_start_proc)

        # for val in bets_olimp.get(key_id, {}).get('kofs', {}).values():
        #     time_change_kof = val.get('hist', {}).get('time_change')
        #     time_change_tot = bets_olimp.get(key_id, {}).get('time_change_total')
        #     avg_change_total = bets_olimp.get(key_id, {}).get('avg_change_total', [])
        #     if round(time_change_tot) < round(time_change_kof):
        #         avg_change_total.append(round(time_change_kof - time_change_tot))
        #         bets_olimp[key_id].update({'time_change_total': round(time_change_kof)})
        #         bets_olimp[key_id].update({'avg_change_total': avg_change_total})

        try:
            for i in list(bets_olimp):
                if str(i) == key_id:
                    for j in list(bets_olimp[i].get('kofs', {})):
                        hide_time = 4
                        if bets_olimp[i].get('place') == 'pre':
                            hide_time = TIMEOUT_PRE_MATCH + hide_time
                        if round(
                                float(time.time() -
                                      float(bets_olimp[i]['kofs'][j].get(
                                          'time_req', 0)))
                        ) > hide_time and bets_olimp[i]['kofs'][j].get(
                                'value', 0) > 0:
                            try:
                                bets_olimp[i]['kofs'][j]['value'] = 0
                                bets_olimp[i]['kofs'][j]['factor'] = 0
                                bets_olimp[i]['kofs'][j]['time_req'] = round(
                                    time.time())
                                if DEBUG:
                                    prnts('2: ' + i + ' ' + j +
                                          ' - выставил в 0')
                                    prnts(
                                        'Олимп, матч:' + key_id +
                                        ' данные по котировке из БК не получены более '
                                        + str(hide_time) +
                                        ' сек., знач. выставил в 0: ' +
                                        str(j) + ' ' + str(i) + ' запрос №: ' +
                                        n)
                            except Exception as e:
                                exc_type, exc_value, exc_traceback = sys.exc_info(
                                )
                                err_str = 'error: ' + str(e) + ' (' + str(
                                    repr(
                                        traceback.format_exception(
                                            exc_type, exc_value,
                                            exc_traceback))) + ')'
                                prnts(
                                    'Олимп, матч:' + key_id +
                                    ' ошибка 1 при удалении старой котирофки: '
                                    + str(err_str) + ' запрос №: ' + n)
                                time.sleep(5)
        except Exception as e:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            err_str = 'error: ' + str(e) + ' (' + str(
                repr(
                    traceback.format_exception(exc_type, exc_value,
                                               exc_traceback))) + ')'
            prnts('Олимп, матч:' + key_id +
                  ' ошибка 2 при удалении старой котирофки: ' + str(err_str) +
                  ' запрос №: ' + n)
            time.sleep(5)
        return time_resp + (time.time() - time_start_proc)
    except OlimpMatchСompleted as e:
        if bets_olimp.get(key_id):
            bets_olimp.pop(key_id)
        raise OlimpMatchСompleted('4 ' + str(e))
    except Exception as e:
        exc_type, exc_value, exc_traceback = sys.exc_info()
        prnts('Олимп, матч: ' + key_id + ' фатальная ошибка:' + str(
            repr(traceback.format_exception(
                exc_type, exc_value, exc_traceback))) + ' запрос №: ' + n +
              '\ndata:' + str(resp_temp))
        # if bets_olimp.get(key_id):
        #     bets_olimp.pop(key_id)
        raise ValueError(e)
Пример #11
0
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)
Пример #12
0
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
Пример #13
0
def get_bets_fonbet(bets_fonbet, match_id, proxies_fonbet, proxy, time_out,
                    pair_mathes, arr_fonbet_top_kofs, place):
    global VICTS, TTO, TTU, TT1O, TT1U, TT2O, TT2U, BASE_LINE, FORA
    global sport_list

    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_bets_fonbet завершен.'
        raise FonbetMatchСompleted(err_str)

    key_id = str(match_id)
    try:
        resp, time_resp = get_match_fonbet(match_id, proxies_fonbet, proxy,
                                           time_out, pair_mathes)
        # if key_id == '18967969':
        #     print(resp)
        time_start_proc = time.time()
        TT = []
        for bet in [TTO, TTU, TT1O, TT1U, TT2O, TT2U, FORA]:
            TT.extend(bet)

        for event in resp.get("events"):
            if event.get('parentId') == 0:
                score = event.get('score', '0:0').replace('-', ':')
                sc1 = 0
                sc2 = 0
                try:
                    scs = re.findall('[0-9]:[0-9]', score)[0]
                    try:
                        sc1 = int(scs.split(':')[0])
                    except Exception as e:
                        prnts('err util_fonbet sc1: ' + str(match_id) +
                              ' score=' + str(score) + ' ' + str(e))
                    try:
                        sc2 = int(scs.split(':')[1])
                    except Exception as e:
                        prnts('err util_fonbet sc2: ' + str(match_id) +
                              ' score=' + str(score) + ' ' + str(e))
                except Exception as e:
                    prnts('err util_fonbet scs: ' + str(match_id) + ' score=' +
                          str(score) + ' ' + str(e))

                timer = event.get('timer', '00:00')
                minute = event.get('timerSeconds', 0) / 60

                skId = event.get('skId')
                liga_id = event.get('sportId')
                skName = event.get('skName')

                minute_complite = if_exists(sport_list, 'fonbet', skId, 'min')
                if minute_complite:
                    if minute >= (minute_complite - 2):
                        err_str = 'Фонбет: матч, ' + skName + ' - ' + str(
                            match_id) + ' завершен, т.к. ' + str(
                                minute_complite - 2) + ' минут прошло.'
                        raise FonbetMatchСompleted(err_str)

                sport_name = event.get('sportName')
                name = event.get('name')
                # print('name:' + str(name))
                # if name == 'SKA-1946 – HK Riga':
                #     import json
                #     print(json.dumps(event, ensure_ascii=False))
                priority = event.get('priority')
                score_1st = event.get('scoreComment', '').replace('-', ':')
                start_time = int(event.get('startTimeTimestamp', 0))
                start_after_min = math.floor(
                    (start_time - int(time.time())) / 60)
                # start_after_min = event.get('time')
                # if DEBUG:
                #     prnts('key_id: {}, start_after_min_cal: {}, start_after_min:{}'.format(key_id, start_after_min_cal, start_after_min))
                if place == 'pre':
                    if start_after_min:
                        if start_after_min <= 5:
                            err_str = 'Фонбет: pre матч, ' + skName + ' - ' + str(
                                match_id) + ' завершен, т.к. ' + str(
                                    start_after_min
                                ) + ' минут до начала матча.'
                            raise FonbetMatchСompleted(err_str)
                if not start_after_min:
                    start_after_min = 0
                if start_after_min <= -120:
                    err_str = 'Фонбет: матч, ' + skName + ' - ' + str(
                        match_id) + ' завершен, т.к. прошло ' + str(
                            abs(start_after_min)) + ' минут от начала матча.'
                    raise FonbetMatchСompleted(err_str)
                # place_in = event.get('place')
                if event.get('parentId'
                             ) == 0 or 'st half' in name or 'nd half' in name:
                    if event.get('parentId') == 0:
                        try:
                            bets_fonbet[key_id].update({
                                'sport_id':
                                skId,
                                'liga_id':
                                liga_id,
                                'place':
                                place,
                                'sport_name':
                                skName,
                                'league':
                                sport_name,
                                'name':
                                name,
                                'priority':
                                priority,
                                'score':
                                score,
                                'score_1st':
                                score_1st,
                                'time':
                                timer,
                                'minute':
                                minute,
                                'start_time':
                                start_time,
                                'start_after_min':
                                start_after_min,
                                'time_req':
                                round(time.time())
                            })
                        except Exception as e:
                            bets_fonbet[key_id] = {
                                'bk_name': 'fonbet',
                                'sport_id': skId,
                                'liga_id': liga_id,
                                'place': place,
                                'sport_name': skName,
                                'league': sport_name,
                                'name': name,
                                'priority': priority,
                                'score': score,
                                'score_1st': score_1st,
                                'time': timer,
                                'minute': minute,
                                'start_time': start_time,
                                'start_after_min': start_after_min,
                                'time_req': round(time.time()),
                                # 'time_change_total': round(time.time()),
                                # 'avg_change_total': [],
                                'kofs': {}
                            }

                    half = ''
                    if 'st half' in name or 'nd half' in name:
                        half = name.replace('st half',
                                            '').replace('nd half', '')

                    for cat in event.get('subcategories', {}):
                        cat_name = cat.get('name')
                        cat_name_list = [
                            '1X2 (90 min)', '1X2', 'Goal - no goal', 'Total',
                            'Totals', 'Team Totals-1', 'Team Totals-2', 'Hcap'
                        ]
                        if place == 'pre':
                            cat_name_list.append('By games')
                        if cat_name in cat_name_list:
                            for kof in cat.get('quotes'):

                                factorId = str(kof.get('factorId'))
                                pValue = kof.get('pValue', '')
                                p = kof.get('p', '').replace('+', '')

                                kof_is_block = kof.get('blocked', False)
                                if kof_is_block:
                                    value = 0
                                else:
                                    value = kof.get('value', 0)

                                for vct in VICTS:
                                    coef = half + str(vct[0])
                                    if str(vct[1]) == factorId:

                                        kof_order = bets_fonbet[key_id].get(
                                            'kofs', {}).get(coef, {}).get(
                                                'hist', {}).get('order', [])
                                        time_change = bets_fonbet[key_id].get(
                                            'kofs',
                                            {}).get(coef,
                                                    {}).get('hist', {}).get(
                                                        'time_change',
                                                        time.time())
                                        avg_change = bets_fonbet[key_id].get(
                                            'kofs', {}).get(coef, {}).get(
                                                'hist',
                                                {}).get('avg_change', [])

                                        try:
                                            if value != kof_order[-1]:
                                                kof_order.append(value)
                                                avg_change.append(0)
                                                time_change = time.time()
                                            elif value == kof_order[-1]:
                                                avg_change[-1] = round(
                                                    time.time() - time_change)
                                        except IndexError:
                                            # firs
                                            kof_order.append(value)
                                            avg_change.append(0)

                                        is_hot = False
                                        if int(factorId
                                               ) in arr_fonbet_top_kofs.get(
                                                   key_id, []):
                                            is_hot = True

                                        is_base_line = False
                                        if int(factorId) in BASE_LINE:
                                            is_base_line = True

                                        bets_fonbet[key_id]['kofs'].update({
                                            coef: {
                                                'time_req':
                                                round(time.time()),
                                                'event':
                                                event.get('id'),
                                                'liga_id':
                                                liga_id,
                                                'value':
                                                value,
                                                'param':
                                                '',
                                                'factor':
                                                factorId,
                                                'base_line':
                                                is_base_line,
                                                'score':
                                                score,
                                                'vector':
                                                get_vector(coef, sc1, sc2),
                                                'is_hot':
                                                is_hot,
                                                'hist': {
                                                    'time_change': time_change,
                                                    'avg_change': avg_change,
                                                    'order': kof_order
                                                }
                                            }
                                        })
                                        # if is_hot:
                                        #     print(bets_fonbet[key_id])

                                for stake in TT:
                                    coef = half + str(
                                        stake[0].format(p))  # + num_team
                                    if str(stake[1]) == factorId:

                                        kof_order = bets_fonbet[key_id].get(
                                            'kofs', {}).get(coef, {}).get(
                                                'hist', {}).get('order', [])
                                        time_change = bets_fonbet[key_id].get(
                                            'kofs',
                                            {}).get(coef,
                                                    {}).get('hist', {}).get(
                                                        'time_change',
                                                        time.time())
                                        avg_change = bets_fonbet[key_id].get(
                                            'kofs', {}).get(coef, {}).get(
                                                'hist',
                                                {}).get('avg_change', [])

                                        try:
                                            if value != kof_order[-1]:
                                                kof_order.append(value)
                                                avg_change.append(0)
                                                time_change = time.time()
                                            elif value == kof_order[-1]:
                                                avg_change[-1] = round(
                                                    time.time() - time_change)
                                        except IndexError:
                                            # firs
                                            kof_order.append(value)
                                            avg_change.append(0)

                                        is_hot = False
                                        if int(factorId
                                               ) in arr_fonbet_top_kofs.get(
                                                   key_id, []):
                                            is_hot = True

                                        bets_fonbet[key_id]['kofs'].update({
                                            coef: {
                                                'time_req':
                                                round(time.time()),
                                                'event':
                                                event.get('id'),
                                                'liga_id':
                                                liga_id,
                                                'value':
                                                value,
                                                'param':
                                                pValue,
                                                'factor':
                                                factorId,
                                                'score':
                                                score,
                                                'vector':
                                                get_vector(coef, sc1, sc2),
                                                'is_hot':
                                                is_hot,
                                                'hist': {
                                                    'time_change': time_change,
                                                    'avg_change': avg_change,
                                                    'order': kof_order
                                                }
                                            }
                                        })

        # for val in bets_fonbet.get(key_id, {}).get('kofs', {}).values():
        #     time_change_kof = val.get('hist', {}).get('time_change')
        #     time_change_tot = bets_fonbet.get(key_id, {}).get('time_change_total')
        #     avg_change_total = bets_fonbet.get(key_id, {}).get('avg_change_total', [])
        #     if round(time_change_tot) < round(time_change_kof):
        #         avg_change_total.append(round(time_change_kof - time_change_tot))
        #         bets_fonbet[key_id].update({'time_change_total': time_change_kof})
        #         bets_fonbet[key_id].update({'avg_change_total': avg_change_total})

        try:
            for i in list(bets_fonbet):
                if str(i) == key_id:
                    for j in list(bets_fonbet[i].get('kofs', {})):
                        hide_time = 4
                        if bets_fonbet[i].get('place') == 'pre':
                            hide_time = TIMEOUT_PRE_MATCH + hide_time
                        if round(
                                float(time.time() -
                                      float(bets_fonbet[i]['kofs'][j].get(
                                          'time_req', 0)))
                        ) > hide_time and bets_fonbet[i]['kofs'][j].get(
                                'value', 0) > 0:
                            try:
                                bets_fonbet[i]['kofs'][j]['value'] = 0
                                if DEBUG:
                                    prnts(
                                        'Фонбет, данные по котировке из БК не получены более '
                                        + str(hide_time) +
                                        ' сек., знач. выставил в 0: ' +
                                        str(j) + ' ' + str(i))
                            except Exception as e:
                                exc_type, exc_value, exc_traceback = sys.exc_info(
                                )
                                err_str = 'error: ' + str(e) + ' (' + str(
                                    repr(
                                        traceback.format_exception(
                                            exc_type, exc_value,
                                            exc_traceback))) + ')'
                                prnts(
                                    'Фонбет, ошибка 1 при удалении старой котирофки: '
                                    + str(err_str))
                                time.sleep(5)
        except Exception as e:
            exc_type, exc_value, exc_traceback = sys.exc_info()
            err_str = 'error: ' + str(e) + ' (' + str(
                repr(
                    traceback.format_exception(exc_type, exc_value,
                                               exc_traceback))) + ')'
            prnts('Фонбет, ошибка 2 при удалении старой котирофки: ' +
                  str(err_str))
            time.sleep(5)
        return time_resp + (time.time() - time_start_proc)
    except FonbetMatchСompleted as e:
        if bets_fonbet.get(key_id):
            bets_fonbet.pop(key_id)
        raise FonbetMatchСompleted('4 ' + str(e))
    except Exception as e:
        prnts(e)
        # if bets_fonbet.get(key_id):
        #     bets_fonbet.pop(key_id)
        raise ValueError(e)
Пример #14
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)
Пример #15
0
def get_next_proxy(proxi_list):
    for n, i in list(enumerate(proxi_list)):
        # prnts('Get next proxy: ' + i, 'hide')
        prnts('Proxy left: ' + str(len(proxi_list) - n) + '/' +
              str(len(proxi_list)))
        yield i.strip()
Пример #16
0
def proxy_push(bk_name):
    bk_name = bk_name.lower()
    copyfile('proxy_by_' + bk_name + '.txt', bk_name + '.proxy')


def cd():
    if platform.system() != 'Windows' and not DEBUG:
        os.chdir(os.path.dirname(os.path.abspath(__file__)))


ol_fl = 'proxy_by_olimp.txt'
fb_fl = 'proxy_by_fonbet.txt'
pn_fl = 'proxy_by_pinnacle.txt'

if __name__ == '__main__':
    prnts('start proxy worker')

    proxy_list = []
    proxy_list_olimp = []
    proxy_list_fonbet = []
    proxy_list = join_proxies_to_file(1)

    prnts('cnt https: ' +
          str(len(list(filter(lambda p: 'https' in p, proxy_list)))))
    prnts('cnt http: ' +
          str(len(list(filter(lambda p: 'http:' in p, proxy_list)))))
    prnts('cnt all: ' + str(len(proxy_list)))
    time.sleep(3)
    # OL
    # proxy_list_ol = get_proxy_from_file('proxy_for_olimp.txt')
    # # proxy_list_ol = (list(filter(lambda p: 'https' in p, proxy_list_ol)))