Skip to content

Commit

Permalink
Update scraper.py
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwoudsma committed Mar 10, 2014
1 parent 4c4eefb commit e532c4f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions scraper.py
Expand Up @@ -147,12 +147,12 @@ def is_number(s):
}

#Store the retrieve data in this loop/iteration to the database
scraperwiki.sqlite.save(unique_keys=['player_team', 'player_round', 'player_id'], data=data, table_name="pcteamplayers")
data.sqlite.save(unique_keys=['player_team', 'player_round', 'player_id'], data=data, table_name="pcteamplayers")

#Query above data to get extra details for the team information
rawbench = scraperwiki.sqlite.select("sum(player_pntscor) as bnchscore from pcteamplayers where player_teamid = '" + source + "' and player_round='" + RoundInfo + "' and player_position='Bankspeler'" )
rawplayers = scraperwiki.sqlite.select("* from pcteamplayers where player_teamid = '" + source + "' and player_round='" + RoundInfo + "'" )
rawbestplayer = scraperwiki.sqlite.select("max(player_pntscor) as best from pcteamplayers where player_teamid = ?",source)
rawbench = data.sqlite.select("sum(player_pntscor) as bnchscore from pcteamplayers where player_teamid = '" + source + "' and player_round='" + RoundInfo + "' and player_position='Bankspeler'" )
rawplayers = data.sqlite.select("* from pcteamplayers where player_teamid = '" + source + "' and player_round='" + RoundInfo + "'" )
rawbestplayer = data.sqlite.select("max(player_pntscor) as best from pcteamplayers where player_teamid = ?",source)
#Make calculation for the best team and system used
i443 = (((getmax(rawplayers, 'Keeper', 1)+getmax(rawplayers, 'Verdediger', 4)+getmax(rawplayers, 'Middenvelder', 3)+getmax(rawplayers, 'Aanvaller', 3))-rawbestplayer[0]['best'])+(2*rawbestplayer[0]['best']))
i442 = (((getmax(rawplayers, 'Keeper', 1)+getmax(rawplayers, 'Verdediger', 4)+getmax(rawplayers, 'Middenvelder', 4)+getmax(rawplayers, 'Aanvaller', 2))-rawbestplayer[0]['best'])+(2*rawbestplayer[0]['best']))
Expand All @@ -161,12 +161,12 @@ def is_number(s):

#Fix lack of update of profcoach.nl due to incompleteness of round
#Solution: Replace the 'RoundScore' with the variable 'baseplayersfix' in the save when saving the datastore
baseplayersfix = scraperwiki.sqlite.select("sum(player_pntscor) as basescore from pcteamplayers where player_teamid = '" + source + "' and player_round='" + RoundInfo + "' and player_position='Basisspeler'" )
baseplayersfix = data.sqlite.select("sum(player_pntscor) as basescore from pcteamplayers where player_teamid = '" + source + "' and player_round='" + RoundInfo + "' and player_position='Basisspeler'" )

#Calculate the best team and get the corresponding system from the list
sMaxScore = max((i443), (i442), (i343), (i352))
sBstSyst = aSyst[index_max([i443, i442, i343, i352])]

# Now single datastore for the team information
scraperwiki.sqlite.save(unique_keys=["team_name", "team_round"], data={"team_id": source, "team_name":get_teamname(tree), "team_round":RoundInfo, "team_roundscore":RoundScore, "team_totalscore": RoundTotalScore, "team_roundposition":RoundPosition, "team_benchscore": rawbench[0]['bnchscore'] ,"team_maxscore":sMaxScore, "team_bestsystem":sBstSyst}, table_name = "pcteams")
data.sqlite.save(unique_keys=["team_name", "team_round"], data={"team_id": source, "team_name":get_teamname(tree), "team_round":RoundInfo, "team_roundscore":RoundScore, "team_totalscore": RoundTotalScore, "team_roundposition":RoundPosition, "team_benchscore": rawbench[0]['bnchscore'] ,"team_maxscore":sMaxScore, "team_bestsystem":sBstSyst}, table_name = "pcteams")
print "Succesfully scraped the details for manager: ", get_teamname(tree)

0 comments on commit e532c4f

Please sign in to comment.