def handle(self, *args, **options): # calling Yahoo API with keys and tokens api = YahooAPI('keyfile.txt', 'tokenfile.txt') # base format for any call BASE_API_CALL = 'http://fantasysports.yahooapis.com/fantasy/v2/{}' # just getting the rosters for each team player_call = BASE_API_CALL.format('league/nba.l.129466/players') print "CALL {}".format(player_call) request = api.request(player_call, params={'format': 'json'}).json() print request['fantasy_content']['league'][1]['players']['2']
def get_important_keyphrases_from_single_doc_yahoo(self, corpus_text, min_len=3, max_len=20): api = YahooAPI(YAHOO_APP_KEY) keywords = [] res = api.keyphrases(corpus_text) for phrase, s in res.iteritems(): kanjimatch = re.search(KANJI, phrase, re.U) hiramatch = re.search(HIRA, phrase, re.U) katamatch = re.search(KATA, phrase, re.U) if not kanjimatch and not hiramatch and not katamatch: continue freq = self.phrase_frequency(phrase, corpus_text) if (freq > 0) and (len(phrase) >= min_len) and (len(phrase) <= max_len) and (phrase not in self.stoplist) and (phrase.lower() != self.query.lower()): kw = Keyword(phrase, float(s)/101, freq) if kw not in keywords: keywords.append(kw) keywords.sort(key=lambda x: x.score, reverse=True) return keywords[:min(len(keywords), self.numberofkeywords)]
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)
def handle(self, *args, **options): logfile = open('rosters/management/commands/errors_load_squads.txt', 'wb') now = datetime.datetime.today() logfile.write('Starting update {}\n\n'.format(now.strftime("%d %B %Y %H:%M"))) logfile.write("flushing squad database\n\n") Squad.objects.all().delete() if options['blank']: for manager_nickname, manager_fullname in Squad.MANAGER_CHOICES: logfile.write("initalizing blank team for {}\n".format(manager_nickname)) squad_obj = Squad( manager=manager_nickname, ) squad_obj.slug = slugify(squad_obj.get_manager_display()) squad_obj.save() else: ## Get managers from Yahoo league # calling Yahoo API with keys and tokens api = YahooAPI('keyfile.txt', 'tokenfile.txt') # base format for any call BASE_API_CALL = 'http://fantasysports.yahooapis.com/fantasy/v2/{}' # just getting the rosters for each team roster_call = BASE_API_CALL.format('team/nba.l.129466.t.{}/roster/') for i in range(1,11): request = api.request(roster_call.format(i), params={'format': 'json'}).json() output = request['fantasy_content']['team'] # initialize all Squads manager_nickname = output[0][19]['managers'][0]['manager']['nickname'] logfile.write("initalizing team for {}\n".format(manager_nickname)) squad_obj = Squad( manager=manager_nickname, ) squad_obj.slug = slugify(squad_obj.get_manager_display()) squad_obj.save() # Yahoo names --> spotrac names translation = { 'Matthew Dellavedova': 'Matt Dellavedova', 'Otto Porter': 'Otto Porter Jr.', 'Ish Smith': 'Ishmael Smith', 'Kentavious Caldwell-Pope': 'Kentavious Caldwell-Pope ', 'Enes Kanter': 'Enes Kanter', 'J.J. Barea': 'Jose Barea', 'Patty Mills': 'Patrick Mills', 'Lou Williams': 'Louis Williams', } # loading players to each roster number_players = int(output[1]['roster']['0']['players']['count']) total_cap_hit = 0 for j in range(0, number_players): player_name = output[1]['roster']['0']['players'][str(j)]['player'][0][2]['name']['full'] if player_name in translation.keys(): player_name = translation[player_name] try: new_player_obj = Player.objects.get(full_name=player_name) new_player_obj.manager = squad_obj squad_obj.total_cap_hit += new_player_obj.salary new_player_obj.save() squad_obj.save() except Player.DoesNotExist: logfile.write("***NO RECORD OF {}***".format(player_name)) # mark last update LastUpdated.objects.all().delete() last_update_obj = LastUpdated( last_update=timezone.now() ) last_update_obj.save()