def request_stats_categories(): access_token = session.get('access_token') r = yahoo.get_stats_categories(access_token) #pprint(r.text) return jsonify(json_util.parse("fantasy_content.game[1].stat_categories" , r.json()))
def request_leagues(): access_token = session.get('access_token') r = yahoo.get_leagues(access_token) print r pprint(r.text) return jsonify(json_util.parse("fantasy_content.users{0}.user[1].games{0}.game[1]", r.json()))
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()))
def get_team_transactions(): access_token = session.get('access_token') team_key = request.args.get('team_key', '', type=str) league_key = request.args.get('league_key', '', type=str) types = request.args.get('types', '', type=str) transaction = Transaction.query.filter_by(key=Transaction.make_key(league_key, team_key)).first() if transaction: # get from db data = json.loads(transaction.json_dump) print "Data from db! %s" % data pass else: r = yahoo.get_team_transactions(access_token, league_key, team_key, types) data = json_util.parse("fantasy_content.leagues{0}.league[1].transactions", r.json()) print "Data added to db! %s" % data # add to the db here. transaction = Transaction(league_key, team_key, types, json.dumps(data)) db.session.add(transaction) db.session.commit() return jsonify(data)
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)
def request_teams(): access_token = session.get('access_token') league_key = request.args.get('league_key', '', type=str) r = yahoo.get_teams(access_token, league_key) return jsonify(json_util.parse("fantasy_content.leagues{0}.league[1]", r.json()))