def getGameStatsFull(country, league, season): et_result = et.extractTeams(country,league,season) cursor = db.fixtures.find({'Country': country, 'League': league, 'Season': season, 'GW':{'$lte':1}}) for doc in cursor: HomeTeam = doc['HomeTeam'] AwayTeam = doc['AwayTeam'] home_team = et_result[HomeTeam].split('/')[-2] away_team = et_result[AwayTeam].split('/')[-2] gameStats = getGameStats(home_team,away_team,league,season) cursor = db.fixtures.find({'Country': country, 'League': league, 'Season': season, 'HomeTeam': HomeTeam, 'AwayTeam': AwayTeam}) gw = cursor[0]['GW'] data = {'Country': country, 'League': league, 'Season': season, 'HomeTeam': HomeTeam, 'AwayTeam': AwayTeam, 'GameStats': gameStats, 'GW': gw} result = db.results.insert_one(data)
def getSquad(country, league, season): et_result = et.extractTeams(country,league,season) sn = season.split('-') sn = sn[1] for Team in et_result.keys(): url = 'http://www.worldfootball.net'+et_result[Team]+sn+'/2/' print ' ',url d = pq(url=url) global Tables global Rows global Cells Tables = [] Rows = [] Cells = [] def callback1(i,elem): print "------ STD TABLE " + str(i) + " ------" global Tables global Rows Rows = []; elem = pq(elem) callback = lambda j, elem: callback2(j,elem, i) elem(("tr")).each(callback) Tables.append(Rows) def callback2(i,elem, i_up): print "------ ROW " + str(i) + " ------" global Rows global Cells Cells = [] rows = pq(elem).children() rows.each(callback3) Rows.append(Cells) def callback3(i,elem): global Cells elem = pq(elem) print elem.text().encode('utf-8') Cells.append(elem) d("div.data table.standard_tabelle").each(callback1) tmp = [ pq(i[0]).text() for i in Tables[0] ] gk = tmp.index('Goalkeeper') defn = tmp.index('Defender') midf = tmp.index('Midfielder') fwd = tmp.index('Forward') try: mgr = tmp.index('Manager') except (ValueError): try: mgr = tmp.index('Ass. Manager') except (ValueError): try: mgr = tmp.index('Goalkeeper-Coach') except (ValueError): mgr = len(tmp) Goalkeepers = [ Push2Mongo(Team,'Goalkeeper',country, league, season,i) for i in Tables[0][gk+1:defn]] Defenders = [ Push2Mongo(Team,'Defender',country, league, season,i) for i in Tables[0][defn+1:midf]] Midfielders = [ Push2Mongo(Team,'Midfielder',country, league, season,i) for i in Tables[0][midf+1:fwd]] Forwards = [ Push2Mongo(Team,'Forward',country, league, season,i) for i in Tables[0][fwd+1:mgr]]