from datetime import datetime
from operator import itemgetter

from yahooapi import YahooAPI

keyfile = 'secrets.txt'
tokenfile = 'tokenfile.txt'

SEED_LEAGUE_KEY = '331.l.1098504'  # current Kimball leauge, build list of leagues based on this # 2014
SEED_LEAGUE_KEY = '348.l.1044567'  # 2015

OUTPUT_CSV_PATH = 'C:\\Users\\Peter\\Dropbox\\ff\\data\\'
#OUTPUT_CSV_PATH = 'data/'

api = YahooAPI(keyfile, tokenfile)

url = 'http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=nfl/leagues'
users_uri = 'http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games'

teams_uri = 'http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/teams'

nfl_games = 'http://fantasysports.yahooapis.com/fantasy/v2/game/nfl'

numpy.set_printoptions(precision=4)


def write_csv_file(filename, year, players):
    filepath = OUTPUT_CSV_PATH + year + '-' + filename + '.csv'
    print str(datetime.now()) + ' Writing file {0}'.format(filepath)