def update_current_gw(): with app.app_context(): currentgw = mongo.db.currentgw eid = currentgw.find_one()['_id'] gw = static_data['current-event'] currentgw.find_one_and_update({'_id': eid}, {'$set': {'gw': gw}}) print 'Updated GW!'
def update_epl_players(): with app.app_context(): eplplayers = mongo.db.eplplayers eplplayers.insert_many([{ 'id': str(player['id']), 'name': player['web_name'], 'team': player['team'] } for player in static_data['elements']])
def update_epl_teams(): with app.app_context(): eplteams = mongo.db.eplteams eplteams.insert_many([{ 'name': str(team['name']), 'short': str(team['short_name']), 'id': team['id'] } for team in static_data['teams']])
def update_ffcteams(): with app.app_context(): ffcteams = mongo.db.ffcteams for team in teamList: teamfile = team.lower() + ".txt" team_file = os.path.join(team_folder, teamfile) team_name, ffc_team = helper.read_in_team(team_file) fplcodes = [player[1][1] for player in ffc_team.items()] ffcteams.insert_one({'team': team, 'codes': fplcodes})
def update_ffc_bench(): with app.app_context(): ffcbench = mongo.db.ffcbench ffcbench.delete_many({}) benchCodes = [ 2447194, 896742, 90373, 343681, 801354, 755683, 672855, 3465481, 351798, 84958, 41341, 16553, 568263, 3758662, 743617, 540557, 673387, 220487, 29057, 514199 ] for team, bcode in zip(teamList, benchCodes): ffcbench.insert_one({'team': team, 'bench': bcode})
def update_ffc_captains(): with app.app_context(): ffccaptains = mongo.db.ffccaptains ffccaptains.delete_many({}) capCodes = [ 5609, 5065, 9350, 223, 776734, 76521, 350414, 1167796, 683730, 16471, 7243, 970393, 559067, 85810, 220254, 667989, 155651, 224000, 7496, 663518 ] for team, capcode in zip(teamList, capCodes): ffccaptains.insert_one({'team': team, 'captain': capcode})
def update_live_points(): with app.app_context(): livepoints = mongo.db.livepoints livepoints.delete_many({}) gw = mongo.db.currentgw.find_one()['gw'] live_url = 'https://fantasy.premierleague.com/drf/event/%d/live' % gw live_data = soupify(live_url)['elements'] livepoints.insert_many({ 'id': str(player[0]), 'fixture': player[1]['explain'][0][1], 'points': player[1]['stats']['total_points'] } for player in live_data.items())
def update_gw_fixtures(): with app.app_context(): gwfixtures = mongo.db.gwfixtures gwfixtures.delete_many({}) gw = mongo.db.currentgw.find_one()['gw'] live_url = 'https://fantasy.premierleague.com/drf/event/%d/live' % gw live_data = soupify(live_url) gwfixtures.insert_many({ 'id': str(fix['id']), 'started': fix['started'], 'home': fix['team_h'], 'away': fix['team_a'] } for fix in live_data['fixtures'])
def update_fpl_managers(): with app.app_context(): fplmanagers = mongo.db.fplmanagers for team in teamList: team = team.lower() + ".txt" team_file = os.path.join(team_folder, team) team_name, ffc_team = helper.read_in_team(team_file) codenametuples = [(player[1][1], player[1][0]) for player in ffc_team.items()] fplmanagers.insert_many([{ 'code': str(tup[0]), 'name': tup[1] } for tup in codenametuples])
def update_epl_players(): with app.app_context(): eplplayers = mongo.db.eplplayers eplplayers.delete_many({}) eplplayers.insert_many([{ 'id': player['id'], 'name': player['first_name'] + ' ' + player['second_name'], 'team': player['team'], 'pos': player['element_type'] } for player in static_data['elements']])
def analyze_tx_history(): with app.app_context(): order_dict = lambda d: OrderedDict( sorted(d.items(), key=lambda x: x[1], reverse=True)) eplplayers = mongo.db.eplplayers playerlist = list(eplplayers.find()) tx_dict = dict() for player in playerlist: player_url = 'https://fantasy.premierleague.com/drf/element-summary/%d' % ( player['id']) player_history = soupify(player_url)['history'] tx_dict[player['name']] = 0 for w in player_history: if w['transfers_balance'] >= 0: tx_dict[player['name']] += 1 else: tx_dict[player['name']] -= 1 import code code.interact(local=locals()) final_dict = order_dict(tx_dict) print take(20, final_dict.iteritems())
def update_ffc_picks(): with app.app_context(): ffcteams = mongo.db.ffcteams ffcpicks = mongo.db.ffcpicks ffcpicks.delete_many({}) gw = mongo.db.currentgw.find_one()['gw'] for team in teamList: obj = ffcteams.find_one({'team': team}) for code in obj['codes']: picks_url = 'https://fantasy.premierleague.com/drf/entry/%d/event/%d/picks' % ( code, gw) try: gw_data = soupify(picks_url) except ValueError: print picks_url playing, bench = [], [] captain = None vicecaptain = None chip = gw_data['active_chip'] points = gw_data['entry_history']['points'] transcost = gw_data['entry_history']['event_transfers_cost'] for pick in gw_data['picks']: if pick['is_captain']: captain = pick['element'] if pick['is_vice_captain']: vicecaptain = pick['element'] if pick['position'] >= 12: bench.append(pick['element']) else: playing.append(pick['element']) ffcpicks.insert_one({ 'code': code, 'points': points, 'captain': captain, 'vicecaptain': vicecaptain, 'chip': chip, 'cost': transcost, 'playing': playing, 'bench': bench })
def update_test(): with app.app_context(): test = mongo.db.test val = test.find_one()['val'] test.find_one_and_update({'var': 'a'}, {'$set': {'val': val + 1}})