def main(): p = MyFantasyLeagueNFLParser() matched_players = [] unmatched_players = [] # MyFantasyLeagueNFLParser.players returns a list of dictionaries # Easier to do name matching if transform to dictionary where full_name is key, player is value fname = 'myfantasyleague_projections/players.xml' positions = ['QB', 'RB', 'WR', 'TE'] players_match_from = { player['full_name']: player for player in p.players(positions=positions, fname=fname) } # now get players from other sites for site, command in commands.items(): result = run_command(command) try: players_to_match = json.loads(result) for player in players_to_match: try: full_name, first_last = NameMatcher.fix_name( player['full_name']) player['full_name'] = full_name player['first_last'] = first_last player = NameMatcher.match_player( to_match=player, match_from=players_match_from, site_id_key='espn_id') if player.get('espn_id') is not None: matched_players.append(player) else: unmatched_players.append(player) except Exception as ie: logging.exception('%s: threw inner exception' % player['full_name']) except Exception as e: logging.exception('%s: threw outer exception') print json.dumps(matched_players, indent=4, sort_keys=True)
def main(): p = MyFantasyLeagueNFLParser() matched_players = [] unmatched_players = [] # MyFantasyLeagueNFLParser.players returns a list of dictionaries # Easier to do name matching if transform to dictionary where full_name is key, player is value fname = 'myfantasyleague_projections/players.xml' positions = ['QB', 'RB', 'WR', 'TE'] players_match_from = {player['full_name']: player for player in p.players(positions=positions, fname=fname)} # now get players from other sites for site, command in commands.items(): result = run_command(command) try: players_to_match = json.loads(result) for player in players_to_match: try: full_name, first_last = NameMatcher.fix_name(player['full_name']) player['full_name'] = full_name player['first_last'] = first_last player = NameMatcher.match_player(to_match=player, match_from=players_match_from, site_id_key='espn_id') if player.get('espn_id') is not None: matched_players.append(player) else: unmatched_players.append(player) except Exception as ie: logging.exception('%s: threw inner exception' % player['full_name']) except Exception as e: logging.exception('%s: threw outer exception') print json.dumps(matched_players, indent=4, sort_keys=True)
mfl = MyFantasyLeagueNFLParser() # MyFantasyLeagueNFLParser.players returns a list of dictionaries # Easier to do name matching if transform to dictionary where full_name is key, player is value fname = 'myfantasyleague_projections/players.xml' positions = ['QB', 'RB', 'WR', 'TE'] players_match_from = { p['full_name']: p for p in mfl.players(positions=positions, fname=fname) } save_json(mfl_json, players_match_from) for i in xrange(len(players)): try: players[i] = NameMatcher.match_player( to_match=players[i], match_from=players_match_from, site_id_key='espn_id') except: pass print json.dumps(players, indent=4, sort_keys=True) jsonfn = args.get('save_json', None) if jsonfn: save_json(jsonfn, players) csvfn = args.get('save_csv', None) if csvfn: save_csv(csvfn, players)
if os.path.exists(mfl_json): with open(mfl_json) as data_file: players_match_from = json.load(data_file) else: mfl = MyFantasyLeagueNFLParser() # MyFantasyLeagueNFLParser.players returns a list of dictionaries # Easier to do name matching if transform to dictionary where full_name is key, player is value fname = 'myfantasyleague_projections/players.xml' positions = ['QB', 'RB', 'WR', 'TE'] players_match_from = {player['full_name']: player for player in mfl.players(positions=positions, fname=fname)} save_json(mfl_json, players_match_from) for i in xrange(len(players)): try: players[i] = NameMatcher.match_player(to_match=players[i], match_from=players_match_from, site_id_key='espn_id') except: pass # dump to stdout pprint.pprint(players, indent=4) # save to file if parameter set jsonfn = args.get('save_json', None) if jsonfn: save_json(jsonfn, players) csvfn = args.get('save_csv', None) if csvfn: save_csv(csvfn, players)