Exemplo n.º 1
0
def upcoming(update, context):
    SCHEDULED = []
    COMPS = []
    SCHEDULED_MSG = 'No Upcoming Matches'
    match_data = FGM.read_data()
    for match in match_data:
        match_date = datetime.datetime.strptime(match['utcDate'],
                                                '%Y-%m-%dT%H:%M:%SZ')
        time_diff = match_date - datetime.datetime.utcnow()
        if -1 < time_diff.days < 3:
            if match['status'] == 'SCHEDULED':
                if match['comp'] not in COMPS:
                    COMPS.append(match['comp'])
                SCHEDULED.append(match)

    if SCHEDULED:
        SCHEDULED_MSG = 'Choose below to see upcoming matches\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [
            InlineKeyboardButton(FGM.find_comp(str(comp)),
                                 callback_data='upcoming' + str(comp))
        ]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id,
                             SCHEDULED_MSG,
                             parse_mode="MARKDOWN",
                             reply_markup=REPLY_MARKUP)
Exemplo n.º 2
0
def recent(update, context):
    FINISHED = []
    COMPS = []
    FINISHED_MSG = 'No Recent Matches'
    match_data = FGM.read_data()
    for match in match_data:
        match_date = datetime.datetime.strptime(match['utcDate'], '%Y-%m-%dT%H:%M:%SZ')
        time_diff = match_date - datetime.datetime.utcnow()
        if -4 < time_diff.days < 0:
            if match['status'] == 'FINISHED':
                if match['comp'] not in COMPS:
                    COMPS.append(match['comp'])
                FINISHED.append(match)

    if FINISHED:
        FINISHED_MSG = 'Select below to get recent matches\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [InlineKeyboardButton(FGM.find_comp(str(comp)), callback_data='recent' + str(comp))]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id, FINISHED_MSG,
                             parse_mode="MARKDOWN", reply_markup=REPLY_MARKUP)
Exemplo n.º 3
0
def update_matches():
    MATCH_LIST = []
    for comp in COMPETITIONS:
        _matches = FGM.matches(comp)
        if 'matches' in _matches:
            _matches = _matches['matches']
            for match in _matches:
                match['comp'] = comp
                MATCH_LIST.append(match)

    if MATCH_LIST:
        FGM.save_data(MATCH_LIST)
Exemplo n.º 4
0
def update_matches():
    for comp in COMPETITIONS:
        _matches = FGM.matches(comp)
        MATCH_DATA = []
        if 'matches' in _matches:
            _matches = _matches['matches']
            for match in _matches:
                d = {
                    'match_id': match['id'],
                    'comp': comp,
                    'matchday': match['season']['currentMatchday'],
                    'date_utc': match['utcDate'],
                    'status': match['status'],
                    'stage': match['stage'],
                    'group': match['group'],
                    'winner': match['score']['winner'],
                    'duration': match['score']['duration'],
                    'full_home': match['score']['fullTime']['homeTeam'],
                    'full_away': match['score']['fullTime']['awayTeam'],
                    'half_home': match['score']['halfTime']['homeTeam'],
                    'half_away': match['score']['halfTime']['awayTeam'],
                    'extra_home': match['score']['extraTime']['homeTeam'],
                    'extra_away': match['score']['extraTime']['awayTeam'],
                    'pen_home': match['score']['penalties']['homeTeam'],
                    'pen_away': match['score']['penalties']['awayTeam'],
                    'home': match['homeTeam']['name'],
                    'away': match['awayTeam']['name'],
                    'home_id': match['homeTeam']['id'],
                    'away_id': match['awayTeam']['id']
                }

                MATCH_DATA.append(d)
        Match.insert_many(MATCH_DATA).on_conflict('replace').execute()
Exemplo n.º 5
0
def update_live():
    live_matches = FGM.live()
    live_matches_ex = Live.select()
    sub_team_list = Sub.select()
    Live.delete().execute()
    if live_matches['games']:
        LIVE_DATA = []
        for match in live_matches['games']:
            d = {
                'league': match['league'],
                'time': match['time'],
                'goals_home': match['goalsHomeTeam'],
                'goals_away': match['goalsAwayTeam'],
                'home': match['homeTeamName'],
                'away': match['awayTeamName']
            }
            LIVE_DATA.append(d)
            for ex in live_matches_ex:
                if match['homeTeamName'] == ex.home and (
                        ex.goals_home != match['goalsHomeTeam']
                        or ex.goals_away != match['goalsAwayTeam']):
                    UPDATE_MSG = f'Goal!\n\n{ex.home}: {ex.goals_home}\n{ex.away}: {ex.goals_away}'
                    for row in sub_team_list:
                        if row.team in (match['homeTeamName'],
                                        match['awayTeamName']):
                            print(UPDATE_MSG)
                            dp.bot.send_message(row.chat_id,
                                                UPDATE_MSG,
                                                parse_mode="MARKDOWN")

        Live.insert_many(LIVE_DATA).on_conflict('replace').execute()
Exemplo n.º 6
0
def live(update, context):
    LIVE = []
    COMPS = []
    LIVE_MSG = 'No live matches! Use /recent or /upcoming to get match list'
    match_data = FGM.read_data()
    for match in match_data:
        if match['status'] == 'IN_PLAY':
            if match['comp'] not in COMPS:
                COMPS.append(match['comp'])
            LIVE.append(match)

    if LIVE:
        LIVE_MSG = 'Select below to get live scores\n'

    KEYBOARD = []

    for comp in COMPS:
        but = [InlineKeyboardButton(FGM.find_comp(str(comp)), callback_data='live' + str(comp))]
        KEYBOARD.append(but)

    REPLY_MARKUP = InlineKeyboardMarkup(KEYBOARD)

    context.bot.send_message(update.effective_chat.id, LIVE_MSG,
                             parse_mode="MARKDOWN", reply_markup=REPLY_MARKUP)
Exemplo n.º 7
0
def team(update, context):
    RESULT_MSG = 'Err!'
    if context.args:
        arg_team_name = ' '.join(context.args)

        try:
            SQUAD = '*SQUAD*:\n'
            res = Team.get(Team.name == arg_team_name)
            sqd = Player.select().where(Player.team == arg_team_name)
            for man in sqd:
                SQUAD += man.name + '\n'
            RESULT_MSG = f'*{res.name}* ({res.tla})\nFounded: _{res.founded}_\nStadium: _{res.stadium}_\n\n' \
                         f'_{res.address}_\n\nPhone: _{res.phone}_\nWebsite: _{res.website}_\nEmail: _{res.email}_\n\n' \
                         f'{SQUAD}'

        except DoesNotExist:
            try:
                team_m = Match.get((Match.home == arg_team_name)
                                   or (Match.away == arg_team_name))
                if team_m:
                    DATA = []
                    SQUAD = '*SQUAD*:\n'
                    if team_m.home == arg_team_name:
                        team_m_id = team_m.home_id
                    else:
                        team_m_id = team_m.away_id

                    team_a = FGM.get_team(team_m_id)

                    Team.insert(team_id=team_a['id'],
                                name=team_a['name'],
                                short_name=team_a['shortName'],
                                tla=team_a['tla'],
                                crest_url=team_a['crestUrl'],
                                address=team_a['address'],
                                phone=team_a['phone'],
                                website=team_a['website'],
                                email=team_a['email'],
                                founded=team_a['founded'],
                                stadium=team_a['venue']).on_conflict(
                                    'replace').execute()

                    for man in team_a['squad']:
                        if man['role'] == 'PLAYER':
                            d = {
                                'player_id': man['id'],
                                'name': man['name'],
                                'team': arg_team_name,
                                'position': man['position'],
                                'dob': man['dateOfBirth'],
                                'born_in': man['countryOfBirth'],
                                'nationality': man['nationality'],
                                'shirt_no': man['shirtNumber'],
                                'role': 'player'
                            }
                            DATA.append(d)

                            SQUAD += man['name'] + '\n'

                    Player.insert_many(DATA).on_conflict('replace').execute()

                    RESULT_MSG = f'*{team_a["name"]}* ({team_a["tla"]})\nFounded: _{team_a["founded"]}_\nStadium: _{team_a["venue"]}_\n\n' \
                                 f'_{team_a["address"]}_\n\nPhone: _{team_a["phone"]}_\nWebsite: _{team_a["website"]}_\nEmail: _{team_a["email"]}_\n\n' \
                                 f'{SQUAD}'

            except DoesNotExist:
                RESULT_MSG = "Can't find team."

    context.bot.send_message(update.effective_chat.id,
                             RESULT_MSG,
                             parse_mode="MARKDOWN")
Exemplo n.º 8
0
def button(update, context):
    query = update.callback_query

    EDIT_MSG = ''

    if 'upcoming' in query.data:
        SCHEDULED = []
        comp = FGM.find_comp(query.data.replace('upcoming', ''))
        EDIT_MSG = 'No Upcoming Matches in ' + comp
        match_data = FGM.read_data()
        for match in match_data:
            match_date = datetime.datetime.strptime(match['utcDate'],
                                                    '%Y-%m-%dT%H:%M:%SZ')
            time_diff = match_date - datetime.datetime.utcnow()
            if -1 < time_diff.days < 3:
                if match['status'] == 'SCHEDULED' and str(
                        match['comp']) == query.data.replace('upcoming', ''):
                    SCHEDULED.append(match)

        if SCHEDULED:
            EDIT_MSG = f'*Upcoming {comp} matches*\n'
            for match in SCHEDULED:
                EDIT_MSG += '---\n_' \
                            + datetime.datetime.strptime(match['utcDate'], '%Y-%m-%dT%H:%M:%SZ').strftime('%A %d %B %l:%M %p') \
                            + '_\n*' \
                            + match['homeTeam']['name'] \
                            + '* vs *' \
                            + match['awayTeam']['name'] \
                            + '*\n'

    elif 'recent' in query.data:
        FINISHED = []
        comp = FGM.find_comp(query.data.replace('recent', ''))
        match_data = FGM.read_data()
        EDIT_MSG = 'No recent matches in ' + comp
        for match in match_data:
            match_date = datetime.datetime.strptime(match['utcDate'],
                                                    '%Y-%m-%dT%H:%M:%SZ')
            time_diff = match_date - datetime.datetime.utcnow()
            if -4 < time_diff.days < 0:
                if match['status'] == 'FINISHED' and str(
                        match['comp']) == query.data.replace('recent', ''):
                    FINISHED.append(match)

        if FINISHED:
            EDIT_MSG = f'*Recent {comp} matches*\n'
            for match in FINISHED:
                EDIT_MSG += '---\n*' \
                            + match['homeTeam']['name'] \
                            + '* _' \
                            + str(match['score']['fullTime']['homeTeam']) \
                            + '_ vs _' \
                            + str(match['score']['fullTime']['awayTeam']) \
                            + '_ *' \
                            + match['awayTeam']['name'] \
                            + '*\n'

    elif 'live' in query.data:
        LIVE = []
        comp = FGM.find_comp(query.data.replace('live', ''))
        match_data = FGM.read_data()
        EDIT_MSG = 'No live matches in ' + comp
        for match in match_data:
            if match['status'] == 'IN_PLAY' and str(
                    match['comp']) == query.data.replace('live', ''):
                LIVE.append(match)

        if LIVE:
            EDIT_MSG = f'*Live {comp} matches*\n'
            for match in LIVE:
                EDIT_MSG += '---\n*' \
                            + match['homeTeam']['name'] \
                            + '* _' + str(match['score']['fullTime']['homeTeam']) \
                            + '_ vs _' \
                            + str(match['score']['fullTime']['awayTeam']) \
                            + '_ *' \
                            + match['awayTeam']['name'] \
                            + '*\n'

    context.bot.edit_message_text(text=EDIT_MSG,
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  parse_mode='MARKDOWN')
Exemplo n.º 9
0
def button(update, context):
    query = update.callback_query

    EDIT_MSG = ''

    if 'upcoming' in query.data:
        SCHEDULED = []
        comp = FGM.find_comp(query.data.replace('upcoming', ''))
        EDIT_MSG = 'No Upcoming Matches in ' + comp
        match_data = Match.select().where(Match.status == 'SCHEDULED')
        for match in match_data:
            match_date = datetime.datetime.strptime(match.date_utc,
                                                    '%Y-%m-%dT%H:%M:%SZ')
            time_diff = match_date - datetime.datetime.utcnow()
            if -1 < time_diff.days < 3:
                if str(match.comp) == query.data.replace('upcoming', ''):
                    SCHEDULED.append(match)

        if SCHEDULED:
            EDIT_MSG = f'*Upcoming {comp} matches*\n'
            for match in SCHEDULED:
                EDIT_MSG += '---\n_' \
                            + datetime.datetime.strptime(match.date_utc, '%Y-%m-%dT%H:%M:%SZ').strftime('%A %d %B %l:%M %p') \
                            + '_\n*' \
                            + match.home \
                            + '* vs *' \
                            + match.away \
                            + '*\n'

    elif 'recent' in query.data:
        FINISHED = []
        comp = FGM.find_comp(query.data.replace('recent', ''))
        match_data = Match.select().where(Match.status == 'FINISHED')
        EDIT_MSG = 'No recent matches in ' + comp
        for match in match_data:
            match_date = datetime.datetime.strptime(match.date_utc,
                                                    '%Y-%m-%dT%H:%M:%SZ')
            time_diff = match_date - datetime.datetime.utcnow()
            if -4 < time_diff.days < 0:
                if str(match.comp) == query.data.replace('recent', ''):
                    FINISHED.append(match)

        if FINISHED:
            EDIT_MSG = f'*Recent {comp} matches*\n'
            for match in FINISHED:
                EDIT_MSG += '---\n*' \
                            + match.home \
                            + '* _' \
                            + str(match.full_home) \
                            + '_ vs _' \
                            + str(match.full_away) \
                            + '_ *' \
                            + match.away \
                            + '*\n'

    elif 'live' in query.data:
        LIVE = []
        comp = ''
        match_data = Live.select()
        EDIT_MSG = 'No live matches in ' + comp
        for match in match_data:
            if match.league == query.data.replace(
                    'live', '') and ('UTC' not in match.time
                                     and 'FT' not in match.time):
                comp = match.league
                LIVE.append(match)

        if LIVE:
            EDIT_MSG = f'*Live {comp} matches*\n'
            for match in LIVE:
                EDIT_MSG += '---\n_' \
                            + str(match.time) \
                            + '_  *' \
                            + match.home \
                            + '* _' \
                            + str(match.goals_home) \
                            + '_ vs _' \
                            + str(match.goals_away) \
                            + '_ *' \
                            + match.away \
                            + '*\n'

    context.bot.edit_message_text(text=EDIT_MSG,
                                  chat_id=query.message.chat_id,
                                  message_id=query.message.message_id,
                                  parse_mode='MARKDOWN')