Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    parser.add_argument('--save_json',
                        help='Filename to save to',
                        required=False)
    args = vars(parser.parse_args())

    projections, rankings = s.get_projections()
    players = p.projections(projections=projections, rankings=rankings)

    # do name matching
    # save parsing time
    mfl_json = 'mfl_players.json'
    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 = {
            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(
    parser.add_argument('--save_json', help='Filename to save to', required=False)
    parser.add_argument('-p', '--players', nargs='+', type=str)
    args = vars(parser.parse_args())

    logging.basicConfig(level=logging.INFO)
    p = FootballOutsidersNFLParser(projections_file = args['infile'])
    players = p.projections()

    # do name matching
    # save parsing time
    mfl_json = 'mfl_players.json'
    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
def main():

    p = MyFantasyLeagueNFLParser()

    # dictionary of dictionaries: key is espn_id, value is player dictionary
    combined = {}

    # now get players from other sites
    for site in ['espn', 'ffnerd',
                 'fboutsiders']:  #, 'ffcalculator', 'fftoday', 'fboutsiders']:

        #using espn_id as the key, so this is first
        if site == 'espn':
            jsonfn = '/home/sansbacon/workspace/python-nfl-projections/combined/espn-projections.json'
            players = load_players(jsonfn)

            for player in players:
                fantasy_points = player.get('fantasy_points')
                player['fantasy_points'] = [fantasy_points]
                combined[player.get('espn_id')] = player

        # now i need to update the existing item with other data
        elif site == 'fboutsiders':
            jsonfn = '/home/sansbacon/workspace/python-nfl-projections/combined/fboutsiders-projections.json'
            players = load_players(jsonfn)

            # if player already exists, update with fboutsiders data
            # if not, then add fboutsiders player to combined
            for player in players:
                combined_player = combined.get(player.get('espn_id'))
                if combined_player:
                    combined_player['risk'] = player.get('risk')
                    combined_player['bye'] = player.get('bye')
                    combined_player['age'] = player.get('age')
                    combined_player['fantasy_points'].append(
                        player.get('fantasy_points'))
                    combined[player.get('espn_id')] = combined_player

                else:
                    fantasy_points = player.get('fantasy_points')
                    player['fantasy_points'] = [fantasy_points]
                    combined[player.get('espn_id')] = player

        elif site == 'ffnerd':
            players = load_players(
                '/home/sansbacon/workspace/python-nfl-projections/combined/ffnerd-projections.json'
            )

            # if player already exists, update with ffnerd data
            # if not, then add ffnerd player to combined
            for player in players:
                combined_player = combined.get(player.get('espn_id'))

                if combined_player:
                    combined_player['stdev_rank'] = player.get('stdev_rank')
                    combined_player['fantasy_points'].append(
                        player.get('fantasy_points'))
                    combined[player.get('espn_id')] = combined_player

                else:
                    fantasy_points = player.get('fantasy_points')
                    player['fantasy_points'] = [fantasy_points]
                    combined[player.get('espn_id')] = player

    for espn_id, player in combined.items():

        sum_fpts = 0.0

        for fpts in player.get('fantasy_points', None):

            try:
                sum_fpts += float(fpts)

            except:
                pass

        if sum_fpts > 0:
            try:
                avg_fpts = sum_fpts / float(len(fpts))
                player['fantasy_points'] = avg_fpts
                combined['espn_id'] = player

            except:
                pass

    print json.dumps(combined, indent=4, sort_keys=True)
    save_json('combined.json', combined.values())
    save_csv('combined.csv', combined.values())