コード例 #1
0
def main():
    twitter_api = tweepy.API(setUpOAuth(), wait_on_rate_limit=True)
    soccer_data = SoccerDataAPI()
    epl = soccer_data.english_premier()
    man_utd = [club for club in epl if club['team'] == "Manchester Utd"][0]

    # calculate the % of matches played
    man_utd['season_progress'] = round(
        (int(man_utd['matches_played']) / 38) * 100, 1)

    # file to store the update counter
    filename = "update_counter.txt"

    update_num = getUpdateNumber(filename)
    points_diff = int(epl[0]['points']) - int(man_utd['points'])
    tweet = constructTweet(man_utd, points_diff, update_num)
    updateNumber(update_num + 1, filename)

    try:
        twitter_api.update_status(tweet)
        print(tweet)
    except tweepy.TweepError as e:
        print(e.reason)
コード例 #2
0
#!J:/WinPython/WPy64-3740/python-3.7.4.amd64/python
'''
    The first line of the Python file indicates where Python is in the PC.
    If Python application file is in the folder J:/WinPython/WPy64-3740/python-3.7.4.amd64 , 
    the first line of Python script should be #!J:/WinPython/WPy64-3740/python-3.7.4.amd64/python
    
    As this web project uses both PHP and Python, and running of Python file is initiated from a PHP file, 
    this is important.
    
'''

from soccer_data_api import SoccerDataAPI
import os

soccer_data = SoccerDataAPI()

if os.path.exists("txt_epl.txt"):
    os.remove("txt_epl.txt")
f = open("txt_epl.txt", "a")
epl = soccer_data.english_premier()
for et in epl:
    str1 = et['team'] + "," + et['pos'] + "," + et['points'] + "," + et[
        'matches_played'] + "," + et['wins'] + "," + et['losses'] + "," + et[
            'goals_for'] + "," + et['goal_diff'] + "\n"
    f.write(str1)
f.close()
コード例 #3
0
ファイル: app.py プロジェクト: andrewbowen19/SoccerDash
def update_league(league):
    # Getting data
    # soccer_data = SoccerDataAPI()
    print(f'League Selected by user {league}')
    soccer_data = SoccerDataAPI()
    data = pd.DataFrame()
    # Checking for each type of league dfata call
    if league == "Premier League":
        data = soccer_data.english_premier()
        # df = pd.DataFrame(data)

    elif league == "La Liga":
        data = soccer_data.la_liga()
        # df = pd.DataFrame(data)

    elif league == "Serie A":
        data = soccer_data.serie_a()
        # df = pd.DataFrame(data)

    elif league == "Ligue 1":
        data = soccer_data.ligue_1()
        # df = pd.DataFrame(data)

    elif league == "Bundesliga":
        data = soccer_data.bundesliga()
        # df = pd.DataFrame(data)

    # Setting up and converting df
    df = pd.DataFrame(data)

    # Reformatting data in table to be plotly friendly
    cols2int = [
        'pos',
        'wins',
        'losses',
        'draws',
        'losses',
        'goals_for',
        'goals_against',
        'goal_diff',
    ]
    for col in cols2int:
        df[col] = df[col].astype(int)

    # Adding top scorer goals
    get_goals = lambda x: int(x['top_scorer'].split(' - ')[1])
    df['top_scorer_goals'] = df.apply(get_goals, axis=1)

    print(f'{league} data:\n', df)

    # Seeting up scatter
    f = px.scatter(df,
                   x="goal_diff",
                   y="points",
                   text='team',
                   title=league,
                   hover_data=['team', 'top_scorer'],
                   labels={
                       'goal_diff': 'Goal Differential',
                       'points': 'Points'
                   })
    f.update_traces(textposition='middle right')
    f.update_yaxes(autorange="reversed")

    # Attack bar graph
    a_bar = px.bar(df,
                   x='team',
                   y='goals_for',
                   title=f'{league} Attack',
                   labels={
                       'team': '',
                       'goals_for': 'Goals For'
                   })

    # Defense Bar graph
    d_bar = px.bar(df,
                   x='team',
                   y='goals_against',
                   title=f'{league} Defense',
                   labels={
                       'team': '',
                       'goals_against': 'Goals Against'
                   })

    # Goal differential bar graph
    diff_bar = px.bar(df,
                      x='team',
                      y='goal_diff',
                      title=f'{league} Goal Differential',
                      labels={
                          'team': '',
                          'goal_diff': 'Goal Differential'
                      })

    s_bar = px.bar(df,
                   x='top_scorer',
                   y='top_scorer_goals',
                   title=f'{league} Top Scorers',
                   hover_data=['team', 'top_scorer'],
                   labels={
                       'top_scorer': 'Player',
                       'top_scorer_goals': 'Goals'
                   })

    # Goal Diff Bar Graph
    return f, a_bar, d_bar, diff_bar, s_bar