def create_entry_from_params(self, params): new_league = League(title = params["title"], description = params["description"], sport = params["sport"], ref_id = params["ref_id"]) new_league.put() return new_league
def select_all(): leagues = [] sql = "SELECT * FROM leagues" results = run_sql(sql) for row in results: league = League(row['name'], row['id']) league.join_code = row['join_code'] leagues.append(league) return leagues
def select(id): league = None sql = "SELECT * FROM leagues WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: league = League(result['name'], result['id']) league.join_code = result['join_code'] return league
def select_by_join_code(join_code): league = None sql = "SELECT * FROM leagues WHERE join_code = %s" values = [join_code] result = run_sql(sql, values) if len(result) > 0: result = result[0] league = League(result['name'], result['id']) league.join_code = result['join_code'] return league
def leagues(player): leagues = [] sql = "SELECT leagues.* FROM leagues INNER JOIN player_leagues ON player_leagues.league_id = leagues.id WHERE player_leagues.player_id = %s" values = [player.id] results = run_sql(sql, values) for row in results: league = League(row['name'], row['id']) league.join_code = row['join_code'] leagues.append(league) return leagues
def get(self, user, league_name): escaped_league_name = urllib.unquote(league_name) league = League.find_by_name(escaped_league_name) if league: self.render_html(league, league.get_teams(), user = user) else: self.set_404("html", user)
def run_simulation(): print(request.values) competition_slug = request.values["league"] competition = load_competitions()[competition_slug] all_teams = load_teams() league = League(competition, all_teams[competition_slug]) league.play_matches() print("Finished simulating league, table below:") for position, table_row in enumerate(league.table, start=1): print(position, table_row["name"], "Played:", table_row["games_played"], "Points:", table_row["points"]) return json.dumps({ "table": league.table, "top_scorer": league.top_scorer, })
def create_league(no_teams, comp_style, no_dates): id = league_type_repo.get_id(no_teams, comp_style, no_dates) league_type = league_type_repo.select(id) name = request.form['name'] sport = request.form['sport'] league = League(league_type, name, sport) new_league = league_repo.save(league) return redirect(f"/edit/league/{new_league.id}/add-teams/{no_teams}/1")
def select(id): league = None sql = "SELECT * FROM leagues WHERE id = %s;" values = [id] result = run_sql(sql, values)[0] if result is not None: league = League(result['league_name'], result['team_id'], result['id']) return league
def select_all(): leagues = [] sql = "SELECT * FROM leagues;" results = run_sql(sql) for row in results: league = League(row['league_name'], row['team_id'], row['id']) leagues.append(league) return leagues
def select(id): league = None sql = "SELECT * FROM leagues WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: league_type = league_type_repo.select(result['league_type_id']) league = League(league_type, result['name'], result['sport'], result['id']) return league
def get(self, user, league_name, team_name, season_name): escaped_league_name = urllib.unquote(league_name) escaped_team_name = urllib.unquote(team_name) escaped_season_name = urllib.unquote(season_name) league = League.find_by_name(escaped_league_name) team = Team.find_by_name(name = escaped_team_name, location = None, league = league) season = Season.find_by_league_and_name(league = league, name = escaped_season_name) if team and season: self.render_html(team = team, season = season, msg = None, user = user) else: self.set_404("html", user)
def select_all(): leagues = [] sql = "SELECT * FROM leagues ORDER BY name ASC" results = run_sql(sql) for result in results: league_type = league_type_repo.select(result['league_type_id']) league = League(league_type, result['name'], result['sport'], result['id']) leagues.append(league) return leagues
class TestLeague(unittest.TestCase): def setUp(self): self.league_1 = League("Wilton Wanderers") def test_league_has_name(self): self.assertEqual("Wilton Wanderers", self.league_1.name) def test_league_has_join_code(self): self.assertEqual(9, len(self.league_1.join_code)) def test_generate_join_code_method(self): code = self.league_1.generate_join_code() self.assertEqual(9, len(code))
def load(self, transformed_response): print "loading...\n" result = {} if transformed_response.get('Person'): self.entities += [Person().extract(transformed_response['Person'])] if transformed_response.get('Author'): self.entities += [Author().extract(transformed_response['Author'])] if transformed_response.get('Actor'): self.entities += [Actor().extract(transformed_response['Actor'])] if transformed_response.get('BusinessPerson'): self.entities += [ BusinessPerson().extract( transformed_response['BusinessPerson']) ] if transformed_response.get('League'): self.entities += [League().extract(transformed_response['League'])] if transformed_response.get('SportsTeam'): self.entities += [ SportsTeam().extract(transformed_response['SportsTeam']) ] if transformed_response.get('Description'): self.entities += [ Description().extract(transformed_response['Description']) ] header = str(self.query) + "(" for entity in self.entities: if entity.__class__.__name__ != "Description": header = header + " " + str(entity.__class__.__name__) header = header + ")" print "----------------------------------" print header print "----------------------------------" for entity in self.entities: entity.print_box() result[entity.__class__.__name__] = entity return result
def new_player_league(): player_id = new_player_league.user_id post_data = request.get_json() if not isinstance(player_id, str): try: active_player = player_repository.select(player_id) league = League(post_data.get('name')) league_repository.save(league) player_league = PlayerLeague(league, active_player) player_league_repository.save(player_league) response = { 'status': 'success', 'message': league.name + ' code: ' + league.join_code } return make_response(jsonify(response)), 201 except Exception as e: response = {'status': 'fail', 'message': e} return make_response(jsonify(response)), 200 else: response = {'status': 'fail', 'message': player_id} return make_response(jsonify(response)), 401
def test_league_has_too_many_teams(self): self.league_too_many_teams = League("Null and Void", 3) self.assertEqual( False, self.league_too_many_teams. check_correct_number_of_teams_for_league_size())
if country in countries: country_latlng = countries[country] else: country_latlng = requests.get( f'https://api.opencagedata.com/geocode/v1/json?q={league_details["strCountry"]}&key=ab82c77042d74ae6aae0bb67ff494887' ).json() country_latlng = country_latlng['results'][0]['bounds'] countries[country] = country_latlng league_object = League( id=league_details['idLeague'], name=league_details['strLeague'], year=league_details['intFormedYear'], country=league_details['strCountry'], description=league_details['strDescriptionEN'], website=league_details['strWebsite'], image=league_details['strLogo'], badge=league_details['strBadge'], lon=(float(country_latlng['northeast']['lng']) + float(country_latlng['southwest']['lng'])) / 2, lat=(float(country_latlng['northeast']['lat']) + float(country_latlng['southwest']['lat'])) / 2) league_object_list.append(league_object) team_list = requests.get( f'https://www.thesportsdb.com/api/v1/json/1/lookup_all_teams.php?id={league["idLeague"]}' ).json() if not team_list['teams']: continue for team in team_list['teams']: if team['idTeam'] not in existing_team_ids and team[ 'strSport'] == 'Soccer':
def validate_params(self, params): return League.validate_params(params)
import json from models.league import League from models.standings import Standings league = League() league.reload() standings = Standings() standings.reload()
# above methods will empty the DB's before they are populated with below info/methods team1 = Team("Aberdeen Roughnecks") team_repository.save(team1) team2 = Team("Dumfries Hunters") team_repository.save(team2) team3 = Team("Clyde Valley Blackhawks") team_repository.save(team3) team4 = Team("West Coast Trojans") team_repository.save(team4) # above code will create each team and save to the DB team_repository.select_all() # above method will display the teams league1 = League("NFC Division 1", team1) league_repository.save(league1) # above will create a league and save to DB league_repository.select_all() # above will take all info that's gone into the league # need to input data for the league (table) to be able to populate it with game_wins game1 = Game(team1, team2, "game week 1", league1) game_repository.save(game1) game2 = Game(team3, team4, "game week 1", league1) game_repository.save(game2) game3 = Game(team1, team3, "game week 2", league1) game_repository.save(game3) game4 = Game(team2, team4, "game week 2", league1)
def setUp(self): self.league = League("NFC Division 1", "Aberdeen Roughnecks")
def load_league(self, league_id): if league_id in LEAGUE_CACHE: return LEAGUE_CACHE[league_id] home_soup = self.get_home_soup(league_id) team_soup = self.get_team_soup(league_id) schedule_soup = self.get_schedule_soup(league_id) league = League() league.id = league_id league.name = self.get_name(home_soup) league.is_major = self.get_is_major(home_soup) league.team_ids = self.get_team_ids(team_soup) league.parent_id = self.get_parent_id(home_soup) league.short_name = self.get_short_name(home_soup) league.team_short_names = self.get_team_short_names(schedule_soup) if league.is_major: waiver_soup = self.get_waiver_wire_soup(league_id) injury_soup = self.get_injury_soup(league_id) finance_soup = self.get_finance_soup(league_id) league.waiver_wire = self.get_waiver_wire(waiver_soup) league.injured_player_ids = self.get_injured_player_ids(injury_soup) league.payrolls = self.get_payrolls(finance_soup) LEAGUE_CACHE[league_id] = league return league
def new_league(): post_data = request.get_json() league = League(post_data.get('name')) league_repository.save(league) return make_response(jsonify(league.__dict__)), 201
def _create_league(self, title, description, sport): league = League(title = title, description = description, sport = sport) league_key = str(league.put()) return league
def setUp(self): self.league_1 = League("Wilton Wanderers")
def setUp(self): self.player_1 = Player("*****@*****.**", "password1", "John", "Smith", "Hopp Suisse") self.league_1 = League("Wilton Wanderers", "1234-5678") self.player_league_1 = PlayerLeague(self.league_1, self.player_1)
def setUp(self): self.league = League("Scottish Premier League", 4) self.league.league_teams = ["Team1", "Team2", "Team3", "Team4"]
'/Users/stanleyhoucke/coding_projects/euros_predictor/app/db/euro2020-matches.csv', mode='r') as csv_file: csv_reader = csv.DictReader(csv_file) for row in csv_reader: date = datetime.strptime(row["Date"], '%d/%m/%Y %H:%M') if len(row["Round Number"]) == 1: team_1 = team_repository.select_by_name(row["Home Team"]) team_2 = team_repository.select_by_name(row["Away Team"]) match = Match(row["Round Number"], date, row["Location"], row["Group"], team_1, team_2) match_repository.save(match) csv_file.close() # Leagues league_1 = League("Overall") league_1.join_code = "0000-0000" league_repository.save(league_1) # Player Leagues player_league_1 = PlayerLeague(league_1, player_1) player_league_repository.save(player_league_1) player_league_2 = PlayerLeague(league_1, player_2) player_league_repository.save(player_league_2) # Player Teams for team in team_repository.select_all(): player_team_repository.save(PlayerTeam(player_1, team)) # Player Groups for group in group_repository.select_all():