Beispiel #1
0
    def GET(self, game_id):
        web.header("Content-Type", "application/json")
        if game_id in dicts_indexed:
            game_data = dicts_indexed[game_id]
            season = probability.season_from_id_str(game_id)
            away = team_format(game_data['away'])
            home = team_format(game_data['home'])
            date = probability.date_from_id(game_id)
            away_score = game_data['away_goal_total']
            home_score = game_data['home_goal_total']
            score = str(away_score) + '-' + str(home_score)

            return json.dumps([season,away,home,date,game_id,score])
        else:
            raise web.notfound()
Beispiel #2
0
teams_fp = open('data/teams.json', 'r')
teams_json = json.load(teams_fp)

def team_format(short_name):
    return "{0} ({1})".format(teams_json[short_name], short_name) if short_name in teams_json else short_name

# games initialization
games_f = open('data/games_goals_pens/games.csv', 'rb')
games_structured = []
gamereader = csv.reader(games_f)
gamereader.next()

for row in gamereader:
    game_id = row[-1]

    season = probability.season_from_id_str(game_id)
    away = team_format(row[1])
    home = team_format(row[4])
    date = probability.date_from_id(game_id)
    away_score = row[2]
    home_score = row[5]
    score = away_score + '-' + home_score

    games_structured.append([season,away,home,date,game_id,score])

app = web.application(urls, globals())

class teams: 
    def GET(self):
        return json.dumps(sorted(map(team_format, teams_json.keys())))