def syncTeams(self,league=DEFAULT_LEAGUE,season=getCurrentSeason()): ''' @league: string containing shortcut of league (e.g. 'bl1') @season: int representing the season request (e.g. 2011) @returns: None This method is responsible for querying openligadb.de for data for all teams in the requested league and requested season. This data is the stored in the local database. This method relies on the syncLeagues method being run beforehand as this method is responsible for creating the team->league relationship ''' session=Session() team = oldb.GetTeamsByLeagueSaison(league,season) league = localService.getLeagueByShortcutSeason(league, season,ret_dict=False) teams = team.Team for team in teams: if teamShortcuts.has_key(int(team.teamID)): shortName = teamShortcuts[int(team.teamID)] else: # mail admin - should add the shortcut to teamShortcuts shortName = None t = session.merge(Team(int(team.teamID),team.teamName.encode('utf-8'), shortName=shortName,iconURL=team.teamIconURL)) session.commit() session.close()
def syncLeagues(self,leagues=DEFAULT_LEAGUES,seasons=DEFAULT_SEASONS): session=Session() league_s = oldb.GetAvailLeagues() leagues = league_s.League for league in leagues: if league.leagueShortcut.lower() in DEFAULT_LEAGUES: if int(league.leagueSaison) in DEFAULT_SEASONS: lleague = session.merge(League(int(league.leagueID), league.leagueName.encode('utf-8'),league.leagueShortcut, int(league.leagueSaison))) team = oldb.GetTeamsByLeagueSaison(lleague.shortcut,lleague.season) teams = team.Team for t in teams: if teamShortcuts.has_key(int(t.teamID)): shortName = teamShortcuts[int(t.teamID)] else: # mail admin - should add the shortcut to teamShortcuts shortName = None team = session.merge(Team(int(t.teamID), t.teamName.encode('utf-8'),shortName=shortName, iconURL=t.teamIconURL)) lleague.teams.append(team) session.commit() session.close()