Пример #1
0
def request_team_stats():
    access_token = session.get('access_token')
    team_key = request.args.get('team_key', '', type=str)
    week = request.args.get('week', 'current', type=str)
    r = yahoo.get_team_stats(access_token, team_key, week)

    print r

    return jsonify(json_util.parse("fantasy_content.teams{0}",r.json()))
Пример #2
0
def get_team_stats():
    access_token = session.get('access_token')
    team_key = request.args.get('team_key', '', type=str)
    end_week = request.args.get('end_week', '', type=int)
    start_week = request.args.get('start_week', '', type=int)

    # add to the db here.
    # team = Team(league_key, team_key, type, data) 
    # db.session.add(team)
    # db.session.commit()

    weeks_back = end_week - start_week;
    stat_ids = []
    team_stats_map = {}
    if weeks_back > 0:
        for week in xrange(start_week, end_week):
            current_week = week
            print current_week
            r = yahoo.get_team_stats(access_token, team_key, str(current_week))
            data = json_util.parse("fantasy_content.teams{0}.team[1].team_stats.stats", r.json())
            for row in data:
                stat_id = row['stat']['stat_id']
                stat_value = row['stat']['value']

                if stat_id not in team_stats_map:
                    team_stats_map[stat_id] = [stat_value]
                    stat_ids.append(stat_id)
                else:
                    team_stats_map[stat_id].append(stat_value)

    team_stats_response_map = {
            'stat_ids'   : stat_ids,
            'team_stats' : team_stats_map,
            'start_week' : start_week,
            'end_week'   : end_week,
            'team_key'   : team_key
            }
    return jsonify(team_stats_response_map)