Example #1
0
 def _update_game(self, game):
     """
     Renew record in soccer table
     :param game:
     :return:
     """
     update_sql = sql.UPDATE_ONE_GAME_BY_LINK.format(
         tbl=myscoresettings.MSC_SOCCER_TABLE, link=game.html_link)
     params = (game.get_game_params())
     run_sql(update_sql, params=params)
Example #2
0
 def _insert_event(self, game, event_type):
     """
     Inser new event for game
     :param game:
     :return:
     """
     insert_sql = sql.INSERT_ONE_EVENT.format(
         tbl=myscoresettings.MSC_EVENT_TABLE)
     params = (*game.get_game_params(), event_type, datetime.now())
     run_sql(insert_sql, params)
     print('New event {}'.format(params))
Example #3
0
 def _insert_league(self, header):
     """
     Insert league in table league
     :param header:
     :return:
     """
     insert_sql = sql.INSERT_LEAGUE_IF_EXIST.format(
         tbl=myscoresettings.MSC_LEAGUE_TABLE,
         link=header.html_link,
         cap=header.caption,
         country=header.country)
     run_sql(insert_sql)
Example #4
0
 def _update_stat(current_game, stat_list):
     update_sql = sql.UPDATE_GAME_STAT.format(
         tbl=myscoresettings.MSC_EVENT_TABLE, link=current_game.html_link)
     home_stat = ''
     away_stat = ''
     for item in stat_list:
         if item:
             tmp = json.loads(item)
             if current_game.team_home in tmp.get('team', ''):
                 home_stat = item
             if current_game.team_away in tmp.get('team', ''):
                 away_stat = item
     params = (home_stat, away_stat)
     run_sql(update_sql, params=params)
Example #5
0
 def _insert_game(self, header, game):
     """
     Insert new game in soccer table
     :param header:
     :param game:
     :return:
     """
     sql_leagie_id = sql.SELECT_LEAGUE_ID.format(
         tbl=myscoresettings.MSC_LEAGUE_TABLE, link=header.html_link)
     result = run_sql(sql_leagie_id)
     if result:
         id_league = result[0]
         insert_sql = sql.INSERT_ONE_GAME.format(
             tbl=myscoresettings.MSC_SOCCER_TABLE, league_id=id_league)
         params = (game.get_game_params())
         self.log.info(params)
         run_sql(insert_sql, params=params)
Example #6
0
 def _get_event_stat(html_link):
     stat = []
     select_sql = sql.SELECT_STAT_BY_LINK.format(
         tbl=myscoresettings.MSC_EVENT_TABLE, link=html_link)
     result = run_sql(select_sql)
     if result:
         stat.append(result[0])
         stat.append(result[1])
     else:
         stat = ['', '']
     return stat
Example #7
0
 def _get_event_odds(html_link):
     odds = Odds()
     select_sql = sql.SELECT_ODDS_BY_LINK.format(
         tbl=myscoresettings.MSC_EVENT_TABLE, link=html_link)
     result = run_sql(select_sql)
     if result:
         odds.live_p1 = result[0]
         odds.live_p2 = result[1]
         odds.live_x = result[2]
         odds.pre_p1 = result[3]
         odds.pre_p2 = result[4]
         odds.pre_x = result[5]
         odds.dog = result[6]
     return odds
Example #8
0
    def calc_stat(self, html_link, dog):
        country_str = ''
        lg_str = ''
        try:
            sql_lg_id = sql.SELECT_LG_ID_AND_COUNTRY.format(link=html_link)
            res_lg_id = run_sql(sql_lg_id)
            if res_lg_id:
                lg = res_lg_id[0]
                country = res_lg_id[1]
            sql_0_1 = sql.SELECT_0_1_BY_COUNTRY.format(country=country,
                                                       dog=dog)
            res_0_1 = run_sql(sql_0_1)
            res_0_1 = res_0_1[0] if res_0_1 else '0'
            sql_0_2 = sql.SELECT_0_2_BY_COUNTRY.format(country=country,
                                                       dog=dog)
            res_0_2 = run_sql(sql_0_2)
            res_0_2 = res_0_2[0] if res_0_2 else '0'
            sql_1_1 = sql.SELECT_1_1_BY_COUNTRY.format(country=country,
                                                       dog=dog)
            res_1_1 = run_sql(sql_1_1)
            res_1_1 = res_1_1[0] if res_1_1 else '0'
            sql_0_1_s = sql.SELECT_0_1_STAY_BY_COUNTRY.format(country=country,
                                                              dog=dog)
            res_0_1_s = run_sql(sql_0_1_s)
            res_0_1_s = res_0_1_s[0] if res_0_1_s else '0'
            if res_0_1 != 0:
                kw = str(round(
                    round(int(res_1_1) / int(res_0_1), 2) * 100)) + '%'
            else:
                kw = '-'
            if res_0_1 != 0:
                kp = str(round(
                    round(int(res_0_2) / int(res_0_1), 2) * 100)) + '%'
            else:
                kp = '-'
            if res_0_1 != 0:
                ks = str(round(
                    round(int(res_0_1_s) / int(res_0_1), 2) * 100)) + '%'
            else:
                ks = '-'
            country_str = 'Всего:{} В:{}({}) П:{}({}) П0:{}({})'.format(
                res_0_1, res_1_1, kw, res_0_2, kp, res_0_1_s, ks)

            sql_0_1 = sql.SELECT_0_1_BY_LG.format(lg=lg, dog=dog)
            res_0_1 = run_sql(sql_0_1)
            res_0_1 = res_0_1[0] if res_0_1 else '0'
            sql_0_2 = sql.SELECT_0_2_BY_LG.format(lg=lg, dog=dog)
            res_0_2 = run_sql(sql_0_2)
            res_0_2 = res_0_2[0] if res_0_2 else '0'
            sql_1_1 = sql.SELECT_1_1_BY_LG.format(lg=lg, dog=dog)
            res_1_1 = run_sql(sql_1_1)
            res_1_1 = res_1_1[0] if res_1_1 else '0'
            sql_0_1_s = sql.SELECT_0_1_STAY_BY_LG.format(lg=lg, dog=dog)
            res_0_1_s = run_sql(sql_0_1_s)
            res_0_1_s = res_0_1_s[0] if res_0_1_s else '0'
            if res_0_1 != 0:
                kw = str(round(
                    round(int(res_1_1) / int(res_0_1), 2) * 100)) + '%'
            else:
                kw = '-'
            if res_0_1 != 0:
                kp = str(round(
                    round(int(res_0_2) / int(res_0_1), 2) * 100)) + '%'
            else:
                kp = '-'
            if res_0_1 != 0:
                ks = str(round(
                    round(int(res_0_1_s) / int(res_0_1), 2) * 100)) + '%'
            else:
                ks = '-'
            lg_str = 'Лига: {} В:{}({}) П:{}({}) П0:{}({})'.format(
                res_0_1, res_1_1, kw, res_0_2, kp, res_0_1_s, ks)
        except Exception:
            self.log.exception('message')
        return country_str + '\n' + lg_str
Example #9
0
 def _update_odds(current_game, odds):
     update_sql = sql.UPDATE_GAME_ODDS.format(
         tbl=myscoresettings.MSC_EVENT_TABLE, link=current_game.html_link)
     params = (odds.get_odds())
     run_sql(update_sql, params=params)
Example #10
0
 def _get_current_game(self, game):
     sql_get_game = sql.SELECT_GAME_BY_LINK.format(
         tbl=myscoresettings.MSC_SOCCER_TABLE, link=game.html_link)
     result = run_sql(sql_get_game)
     return result