def setUp(self): self.winner = ObjectId() self.loser = ObjectId() self.other_player = ObjectId() self.match_id = 1 self.match_id2 = 2 self.excluded1 = False self.excluded2 = True self.match_result = Match(match_id=self.match_id, winner=self.winner, loser=self.loser, excluded=self.excluded1) self.other_match_result = Match(match_id=self.match_id2, winner=self.winner, loser=self.other_player, excluded=self.excluded2) self.match_result_json_dict = { 'match_id': self.match_id, 'winner': self.winner, 'loser': self.loser, 'excluded': self.excluded1 }
def getAllMatches(self): """ Create classes from list :return: """ res = [] for m in self.matches: res.append(Match(m[0], m[1], m[2], m[3], m[4], m[5])) return res
def scrape_results(league_link, league, season): teams = db.get_teams_by_season(season) matches_soup = get_season_matches_as_html(league_link, league.name) matches = [] for match_div in matches_soup: date_time = match_div.find('div', class_='event__time').text date = get_match_year(season, date_time.split(' ')[0]) home_team_name = match_div.find('div', class_='event__participant--home').text away_team_name = match_div.find('div', class_='event__participant--away').text home_team = find_team_by_name(teams, home_team_name) away_team = find_team_by_name(teams, away_team_name) score = match_div.find('div', class_='event__scores').text.replace(' ', '').split('-') home_team_score = score[0] away_team_score = score[1] match = Match(season=season, date=date, home_team=home_team, away_team=away_team, home_team_score=home_team_score, away_team_score=away_team_score) matches.append(match) db.save_matches(matches)
def setUp(self): self.mongo_client.drop_database(DATABASE_NAME) self.player_1_id = ObjectId() self.player_2_id = ObjectId() self.player_3_id = ObjectId() self.player_4_id = ObjectId() self.player_5_id = ObjectId() self.player_1 = Player(name='gaR', aliases=['gar', 'garr'], ratings={ 'norcal': Rating(), 'texas': Rating() }, regions=['norcal', 'texas'], id=self.player_1_id) self.player_2 = Player(name='sfat', aliases=['sfat', 'miom | sfat'], ratings={'norcal': Rating()}, regions=['norcal'], id=self.player_2_id) self.player_3 = Player(name='mango', aliases=['mango', 'gar'], ratings={'norcal': Rating(mu=2, sigma=3)}, regions=['socal'], id=self.player_3_id) self.player_4 = Player(name='shroomed', aliases=['shroomed'], ratings={'norcal': Rating()}, regions=['norcal'], id=self.player_4_id) self.player_5 = Player(name='pewpewu', aliases=['pewpewu'], ratings={'norcal': Rating()}, regions=['norcal', 'socal'], id=self.player_5_id) self.merge_player_1 = Player(name='CLGsFaT', aliases=['clg | sfat'], ratings={'norcal': Rating()}, regions=['norcal'], id=ObjectId()) # only includes players 1-3 self.players = [self.player_1, self.player_2, self.player_3] self.tournament_id_1 = ObjectId() self.tournament_type_1 = 'tio' self.tournament_raw_id_1 = ObjectId() self.tournament_date_1 = datetime(2013, 10, 16) self.tournament_name_1 = 'tournament 1' self.tournament_players_1 = [ self.player_1_id, self.player_2_id, self.player_3_id, self.player_4_id ] self.tournament_matches_1 = [ Match(winner=self.player_1_id, loser=self.player_2_id), Match(winner=self.player_3_id, loser=self.player_4_id) ] self.tournament_regions_1 = ['norcal'] # tournament 2 is earlier than tournament 1, but inserted after self.tournament_id_2 = ObjectId() self.tournament_type_2 = 'challonge' self.tournament_raw_id_2 = ObjectId() self.tournament_date_2 = datetime(2013, 10, 10) self.tournament_name_2 = 'tournament 2' self.tournament_players_2 = [ self.player_5_id, self.player_2_id, self.player_3_id, self.player_4_id ] self.tournament_matches_2 = [ Match(winner=self.player_5_id, loser=self.player_2_id), Match(winner=self.player_3_id, loser=self.player_4_id) ] self.tournament_regions_2 = ['norcal', 'texas'] self.tournament_1 = Tournament(id=self.tournament_id_1, name=self.tournament_name_1, type=self.tournament_type_1, date=self.tournament_date_1, regions=self.tournament_regions_1, raw_id=self.tournament_raw_id_1, players=self.tournament_players_1, matches=self.tournament_matches_1) self.tournament_2 = Tournament(id=self.tournament_id_2, name=self.tournament_name_2, type=self.tournament_type_2, date=self.tournament_date_2, regions=self.tournament_regions_2, raw_id=self.tournament_raw_id_2, players=self.tournament_players_2, matches=self.tournament_matches_2) self.tournament_ids = [self.tournament_id_1, self.tournament_id_2] self.tournaments = [self.tournament_1, self.tournament_2] self.pending_tournament_id_1 = ObjectId() self.pending_tournament_type_1 = 'tio' self.pending_tournament_raw_id_1 = ObjectId() self.pending_tournament_date_1 = datetime(2013, 10, 11) self.pending_tournament_name_1 = 'pending tournament 1' self.pending_tournament_players_1 = [ self.player_1.name, self.player_2.name, self.player_3.name, self.player_4.name ] self.pending_tournament_matches_1 = [ AliasMatch(winner=self.player_1.name, loser=self.player_2.name), AliasMatch(winner=self.player_3.name, loser=self.player_4.name) ] self.pending_tournament_regions_1 = ['norcal'] self.pending_tournament_1 = PendingTournament( id=self.pending_tournament_id_1, name=self.pending_tournament_name_1, type=self.pending_tournament_type_1, date=self.pending_tournament_date_1, regions=self.pending_tournament_regions_1, raw_id=self.pending_tournament_raw_id_1, players=self.pending_tournament_players_1, matches=self.pending_tournament_matches_1) self.pending_tournaments = [self.pending_tournament_1] self.ranking_entry_1 = RankingEntry(rank=1, player=self.player_1_id, rating=20) self.ranking_entry_2 = RankingEntry(rank=2, player=self.player_2_id, rating=19) self.ranking_entry_3 = RankingEntry(rank=3, player=self.player_3_id, rating=17.5) self.ranking_entry_4 = RankingEntry(rank=3, player=self.player_4_id, rating=16.5) self.ranking_time_1 = datetime(2013, 4, 20) self.ranking_time_2 = datetime(2013, 4, 21) self.ranking_1 = Ranking(id=ObjectId(), region='norcal', time=self.ranking_time_1, tournaments=self.tournament_ids, ranking=[ self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_3 ]) self.ranking_2 = Ranking(id=ObjectId(), region='norcal', time=self.ranking_time_2, tournaments=self.tournament_ids, ranking=[ self.ranking_entry_1, self.ranking_entry_2, self.ranking_entry_4 ]) self.ranking_3 = Ranking( id=ObjectId(), region='norcal', time=self.ranking_time_2, tournaments=self.tournament_ids, ranking=[self.ranking_entry_1, self.ranking_entry_2]) self.rankings = [self.ranking_1, self.ranking_2, self.ranking_3] self.user_id_1 = 'abc123' self.user_admin_regions_1 = ['norcal', 'texas'] self.user_1 = User(id=self.user_id_1, admin_regions=self.user_admin_regions_1, username='******', salt='nacl', hashed_password='******') self.user_id_2 = 'asdfasdf' self.user_full_name_2 = 'Full Name' self.user_admin_regions_2 = [] self.user_2 = User(id=self.user_id_2, admin_regions=self.user_admin_regions_2, username=self.user_full_name_2, salt='nacl', hashed_password='******') self.users = [self.user_1, self.user_2] self.region_1 = Region(id='norcal', display_name='Norcal') self.region_2 = Region(id='texas', display_name='Texas') self.regions = [self.region_1, self.region_2] for region in self.regions: Dao.insert_region(region, self.mongo_client, database_name=DATABASE_NAME) self.norcal_dao = Dao('norcal', self.mongo_client, database_name=DATABASE_NAME) for player in self.players: self.norcal_dao.insert_player(player) for tournament in self.tournaments: self.norcal_dao.insert_tournament(tournament) for pending_tournament in self.pending_tournaments: self.norcal_dao.insert_pending_tournament(pending_tournament) for ranking in self.rankings: self.norcal_dao.insert_ranking(ranking) for user in self.users: self.norcal_dao.insert_user(user)
def create_matches(self): return [ Match(group="A", home_team="Бразилия", guest_team="Хорватия", start=datetime.combine(date(2014, 06, 12), time(23, 0))), Match(group="A", home_team="Мексика", guest_team="Камерун", start=datetime.combine(date(2014, 06, 13), time(19, 0))), Match(group="B", home_team="Испания", guest_team="Нидерланды", start=datetime.combine(date(2014, 06, 13), time(22, 0))), Match(group="B", home_team="Чили", guest_team="Австралия", start=datetime.combine(date(2014, 06, 14), time(1, 0))), Match(group="C", home_team="Колумбия", guest_team="Греция", start=datetime.combine(date(2014, 06, 14), time(19, 0))), Match(group="D", home_team="Уругвай", guest_team="Коста-Рика", start=datetime.combine(date(2014, 06, 14), time(22, 0))), Match(group="D", home_team="Англия", guest_team="Италия", start=datetime.combine(date(2014, 06, 15), time(1, 0))), Match(group="C", home_team="Кот д'Ивуар", guest_team="Япония", start=datetime.combine(date(2014, 06, 15), time(4, 0))), Match(group="E", home_team="Швейцария", guest_team="Эквадор", start=datetime.combine(date(2014, 06, 15), time(19, 0))), Match(group="E", home_team="Франция", guest_team="Гондурас", start=datetime.combine(date(2014, 06, 15), time(22, 0))), Match(group="F", home_team="Аргентина", guest_team="Босния", start=datetime.combine(date(2014, 06, 16), time(1, 0))), Match(group="G", home_team="Германия", guest_team="Португалия", start=datetime.combine(date(2014, 06, 16), time(19, 0))), Match(group="F", home_team="Иран", guest_team="Нигерия", start=datetime.combine(date(2014, 06, 16), time(22, 0))), Match(group="G", home_team="Гана", guest_team="США", start=datetime.combine(date(2014, 06, 17), time(1, 0))), Match(group="H", home_team="Бельгия", guest_team="Алжир", start=datetime.combine(date(2014, 06, 17), time(19, 0))), Match(group="A", home_team="Бразилия", guest_team="Мексика", start=datetime.combine(date(2014, 06, 17), time(22, 0))), Match(group="H", home_team="Россия", guest_team="Южная Корея", start=datetime.combine(date(2014, 06, 18), time(1, 0))), Match(group="B", home_team="Австралия", guest_team="Нидерланды", start=datetime.combine(date(2014, 06, 18), time(19, 0))), Match(group="B", home_team="Испания", guest_team="Чили", start=datetime.combine(date(2014, 06, 18), time(22, 0))), Match(group="A", home_team="Камерун", guest_team="Хорватия", start=datetime.combine(date(2014, 06, 19), time(1, 0))), Match(group="C", home_team="Колумбия", guest_team="Кот д'Ивуар", start=datetime.combine(date(2014, 06, 19), time(19, 0))), Match(group="D", home_team="Уругвай", guest_team="Англия", start=datetime.combine(date(2014, 06, 19), time(22, 0))), Match(group="C", home_team="Япония", guest_team="Греция", start=datetime.combine(date(2014, 06, 20), time(1, 0))), Match(group="D", home_team="Италия", guest_team="Коста-Рика", start=datetime.combine(date(2014, 06, 20), time(19, 0))), Match(group="E", home_team="Швейцария", guest_team="Франция", start=datetime.combine(date(2014, 06, 20), time(22, 0))), Match(group="E", home_team="Гондурас", guest_team="Эквадор", start=datetime.combine(date(2014, 06, 21), time(1, 0))), Match(group="F", home_team="Аргентина", guest_team="Иран", start=datetime.combine(date(2014, 06, 21), time(19, 0))), Match(group="G", home_team="Германия", guest_team="Гана", start=datetime.combine(date(2014, 06, 21), time(22, 0))), Match(group="F", home_team="Нигерия", guest_team="Босния", start=datetime.combine(date(2014, 06, 22), time(1, 0))), Match(group="H", home_team="Бельгия", guest_team="Россия", start=datetime.combine(date(2014, 06, 22), time(19, 0))), Match(group="H", home_team="Южная Корея", guest_team="Алжир", start=datetime.combine(date(2014, 06, 22), time(22, 0))), Match(group="G", home_team="США", guest_team="Португалия", start=datetime.combine(date(2014, 06, 23), time(1, 0))), Match(group="B", home_team="Австралия", guest_team="Испания", start=datetime.combine(date(2014, 06, 23), time(19, 0))), Match(group="B", home_team="Нидерланды", guest_team="Чили", start=datetime.combine(date(2014, 06, 23), time(19, 0))), Match(group="A", home_team="Камерун", guest_team="Бразилия", start=datetime.combine(date(2014, 06, 23), time(23, 0))), Match(group="A", home_team="Хорватия", guest_team="Мексика", start=datetime.combine(date(2014, 06, 23), time(23, 0))), Match(group="D", home_team="Коста-Рика", guest_team="Англия", start=datetime.combine(date(2014, 06, 24), time(19, 0))), Match(group="D", home_team="Италия", guest_team="Уругвай", start=datetime.combine(date(2014, 06, 24), time(19, 0))), Match(group="C", home_team="Греция", guest_team="Кот д'Ивуар", start=datetime.combine(date(2014, 06, 24), time(23, 0))), Match(group="C", home_team="Япония", guest_team="Колумбия", start=datetime.combine(date(2014, 06, 24), time(23, 0))), Match(group="F", home_team="Нигерия", guest_team="Аргентина", start=datetime.combine(date(2014, 06, 25), time(19, 0))), Match(group="F", home_team="Босния", guest_team="Иран", start=datetime.combine(date(2014, 06, 25), time(19, 0))), Match(group="E", home_team="Гондурас", guest_team="Швейцария", start=datetime.combine(date(2014, 06, 25), time(23, 0))), Match(group="E", home_team="Эквадор", guest_team="Франция", start=datetime.combine(date(2014, 06, 25), time(23, 0))), Match(group="G", home_team="США", guest_team="Германия", start=datetime.combine(date(2014, 06, 26), time(19, 0))), Match(group="G", home_team="Португалия", guest_team="Гана", start=datetime.combine(date(2014, 06, 26), time(19, 0))), Match(group="H", home_team="Алжир", guest_team="Россия", start=datetime.combine(date(2014, 06, 26), time(23, 0))), Match(group="H", home_team="Южная Корея", guest_team="Бельгия", start=datetime.combine(date(2014, 06, 26), time(23, 0))) ]
def setUp(self): self.player_1_id = ObjectId() self.player_2_id = ObjectId() self.player_3_id = ObjectId() self.player_4_id = ObjectId() self.player_5_id = ObjectId() self.player_6_id = ObjectId() self.player_1 = Player(name='gar', id=self.player_1_id) self.player_2 = Player(name='sfat', id=self.player_2_id) self.player_3 = Player(name='shroomed', id=self.player_3_id) self.player_4 = Player(name='ppu', id=self.player_4_id) self.player_5 = Player(name='ss', id=self.player_5_id) self.player_6 = Player(name='hmw', id=self.player_6_id) self.match_1 = Match(winner=self.player_1_id, loser=self.player_2_id) self.match_2 = Match(winner=self.player_3_id, loser=self.player_4_id) self.match_1 = AliasMatch(winner=self.player_1.name, loser=self.player_2.name) self.match_2 = AliasMatch(winner=self.player_3.name, loser=self.player_4.name) self.alias_to_id_map = [ AliasMapping(player_alias=self.player_1.name, player_id=self.player_1_id), AliasMapping(player_alias=self.player_2.name, player_id=self.player_2_id), AliasMapping(player_alias=self.player_3.name, player_id=self.player_3_id), AliasMapping(player_alias=self.player_4.name, player_id=self.player_4_id) ] self.id = ObjectId() self.type = 'tio' self.raw_id = ObjectId() self.date = datetime.now() self.name = 'tournament' self.players = [ self.player_1.name, self.player_2.name, self.player_3.name, self.player_4.name ] self.matches = [self.match_1, self.match_2] self.regions = ['norcal', 'texas'] self.url = 'http://challonge.com/test' self.excluded = False self.pending_tournament_json_dict = { '_id': self.id, 'type': self.type, 'raw_id': self.raw_id, 'date': self.date, 'name': self.name, 'players': self.players, 'matches': [m.dump(context='db') for m in self.matches], 'regions': self.regions, 'alias_to_id_map': [am.dump(context='db') for am in self.alias_to_id_map], 'excluded': False, 'url': self.url } self.pending_tournament = PendingTournament( id=self.id, name=self.name, type=self.type, date=self.date, regions=self.regions, url=self.url, raw_id=self.raw_id, players=self.players, matches=self.matches, excluded=self.excluded, alias_to_id_map=self.alias_to_id_map)
def setUp(self): self.player_1_id = ObjectId() self.player_2_id = ObjectId() self.player_3_id = ObjectId() self.player_4_id = ObjectId() self.player_5_id = ObjectId() self.player_6_id = ObjectId() self.player_1 = Player(name='gar', id=self.player_1_id) self.player_2 = Player(name='sfat', id=self.player_2_id) self.player_3 = Player(name='shroomed', id=self.player_3_id) self.player_4 = Player(name='ppu', id=self.player_4_id) self.player_5 = Player(name='ss', id=self.player_5_id) self.player_6 = Player(name='hmw', id=self.player_6_id) self.match_1 = Match(winner=self.player_1_id, loser=self.player_2_id, match_id=1) self.match_2 = Match(winner=self.player_3_id, loser=self.player_4_id, match_id=2) self.alias_to_id_map = [ AliasMapping(player_alias=self.player_2.name, player_id=self.player_2_id), AliasMapping(player_alias=self.player_1.name, player_id=self.player_1_id), AliasMapping(player_alias=self.player_3.name, player_id=self.player_3_id), AliasMapping(player_alias=self.player_4.name, player_id=self.player_4_id) ] self.id = ObjectId() self.type = 'tio' self.raw_id = ObjectId() self.date = datetime.now() self.name = 'tournament' self.url = "challonge.com/tournament" self.player_ids = [ self.player_1_id, self.player_2_id, self.player_3_id, self.player_4_id ] self.players = [ self.player_1, self.player_2, self.player_3, self.player_4 ] self.matches = [self.match_1, self.match_2] self.regions = ['norcal', 'texas'] self.tournament_json_dict = { '_id': self.id, 'type': self.type, 'raw_id': self.raw_id, 'date': self.date, 'name': self.name, 'url': self.url, 'players': self.player_ids, 'orig_ids': self.player_ids, 'matches': [m.dump(context='db') for m in self.matches], 'regions': self.regions } self.tournament = Tournament(id=self.id, name=self.name, type=self.type, date=self.date, regions=self.regions, url=self.url, raw_id=self.raw_id, players=self.player_ids, orig_ids=self.player_ids, matches=self.matches)
def add_match(): """ We create a match object, 2 teamps and get the players """ form = Form_add_match(request.form) if request.method == "POST": # Creation object Match match = Match() # Get the players team1_players = request.form.getlist("team1_select") team2_players = request.form.getlist("team2_select") team1_players = form.team1_select.data team2_players = form.team2_select.data print(team1_players) print(team2_players) # Get the results of the match # result1 = request.form.get("result1") # result2 = request.form.get("result2") result1 = form.result1.data result2 = form.result2.data #Creation of the teams team1 = Team(result=result1) team2 = Team(result=result2) # # Cration association object : play for each player in the match # team1play1 = Play(result=result1, match_id=match.id) # team2play1 = Play(result=result2, match_id=match.id) # Set the player and add to the match team1player1 = Player.query.filter_by(id=int(team1_players[0])).first() team2player1 = Player.query.filter_by(id=int(team2_players[0])).first() team1.players.append(team1player1) team2.players.append(team2player1) # Set the second players if they played if len(team1_players) > 1: team1player2 = Player.query.filter_by( id=int(team1_players[1])).first() team1.players.append(team1player2) if len(team2_players) > 1: team2player2 = Player.query.filter_by( id=int(team2_players[1])).first() team2.players.append(team2player2) # Add the both teams to the matchs match.teams.append(team1) match.teams.append(team2) # Add in the database and commit db.session.add(match) db.session.commit() return redirect(url_for(".show_matchs")) else: players = Player.query.all() list_players = [] for player in players: list_players.append(player.get_tuple_player()) form.team1_select.choices = list_players form.team2_select.choices = list_players return render_template("add_match.html", players=players, form=form)
def fillOutMatch(SESSION, match, name, id): user = SESSION.query(User).filter(User.id == id).filter( User.name == name).one() d = datetime.strptime(match['started_at'], "%Y-%m-%dT%H:%M:%S%z") _m = SESSION.query(Match).filter(Match.user_id==user.id).\ filter(Match.user_name==user.name).\ filter(Match.date==d).\ filter(Match.id==match['match_id']).all() #Don't add duplicate data if len(_m) > 0: #my_print("duplicate data!") return True participant = match['participant'] stats = participant['stats'] combat = stats['combat'] m = Match() m.pubg_id = participant['_id'] # 2018-01-24T03:10:17+0000 m.date = d m.id = match['match_id'] m.mode = match['mode'] m.queue_size = match['queue_size'] m.rank = stats['rank'] m.rating_delta = stats['rating_delta'] m.boosts = combat['boosts'] m.damage = combat['damage']['damage_dealt'] m.knocks = combat['dbno']['knock_downs'] m.revives = combat['dbno']['revives'] m.death_type = combat['death_type'] m.ride_distance = combat['distance_traveled']['ride_distance'] m.walk_distance = combat['distance_traveled']['walk_distance'] m.distance_traveled = m.ride_distance + m.walk_distance m.heals = combat['heals'] m.assists = combat['kda']['assists'] m.headshot_kills = combat['kda']['headshot_kills'] m.kill_steaks = combat['kda']['kill_steaks'] m.kills = combat['kda']['kills'] m.longest_kill = combat['kda']['longest_kill'] m.road_kills = combat['kda']['road_kills'] m.team_kills = combat['kda']['team_kills'] m.kda = m.kills + m.assists m.kill_place = combat['kill_place'] m.most_damage = combat['most_damage'] m.time_survived = combat['time_survived'] m.vehicle_destroys = combat['vehicle_destroys'] m.weapon_acquired = combat['weapon_acquired'] m.win_place = combat['win_place'] m.user_id = user.id m.user_name = user.name m.user.append(user) user.matches.append(m) SESSION.add(m) return False
def admin(): """Admin page""" if users.is_current_user_admin(): logout_url = users.create_logout_url('/admin') method = request.args.get('m', '') logging.info('Method name:[%s]' % method) if method == 'dropdb': match_keys = Match.query().fetch(keys_only=True) ndb.delete_multi(match_keys) return render_template('admin.html', msg='Matches all deleted!', logout_url=logout_url) if method == 'dropbet': if not isLocal(): abort(401) bet_keys = Bet.query().fetch(keys_only=True) ndb.delete_multi(bet_keys) return render_template('admin.html', msg='Bet all deleted!', logout_url=logout_url) elif method == 'initdb': with open('worldcup2014-group-stage.csv', 'rb') as csvfile: spamreader = csv.reader(csvfile) for row in spamreader: match = Match(matchid=int(row[0]), date=datetime.strptime( str(row[1]), "%m/%d/%Y %H:%M"), stage=row[5], team_a=row[2], team_b=row[3], score_a=None, score_b=None, extra_a=None, extra_b=None, penalty_a=None, penalty_b=None) match.put() return render_template('admin.html', msg='Matches imported!', logout_url=logout_url) elif method == 'initdb2': with open('worldcup2014-knockoff-stage.csv', 'rb') as csvfile: spamreader = csv.reader(csvfile) for row in spamreader: match = Match(matchid=int(row[0]), date=datetime.strptime( str(row[1]), "%m/%d/%Y %H:%M"), stage=row[5], team_a='winner of ' + row[2], team_b='winner of ' + row[3], score_a=None, score_b=None, extra_a=None, extra_b=None, penalty_a=None, penalty_b=None) match.put() return render_template('admin.html', msg='Matches imported!', logout_url=logout_url) elif method == 'randombetwithknownuser': for useremail in known_users.keys(): #drop existing first existing_bets = Bet.query(Bet.useremail == useremail).fetch( keys_only=True) ndb.delete_multi(existing_bets) #new data digits = 21 uid = str(int(random.random() * 10**digits)).rjust(digits, '0') matches = Match.query().fetch() for match in matches: bet = Bet(userid=uid, useremail=useremail, bet_match_id=int(match.matchid), bet_amount=1, score_a=random.randint(0, 3), score_b=random.randint(0, 3), extra_a=None, extra_b=None, penalty_a=None, penalty_b=None) bet.put() return render_template( 'admin.html', msg='simulated bets for known user has been generated!', logout_url=logout_url) elif method == 'randombet': digits = 21 uid = str(int(random.random() * 10**digits)).rjust(digits, '0') digits = 3 email = '*****@*****.**' % int(random.random() * 10**digits) matches = Match.query().fetch() for match in matches: bet = Bet(userid=uid, useremail=email, bet_match_id=int(match.matchid), bet_amount=1, score_a=random.randint(0, 3), score_b=random.randint(0, 3), extra_a=None, extra_b=None, penalty_a=None, penalty_b=None) bet.put() return render_template( 'admin.html', msg='simulated bets for %s has been generated!' % uid, logout_url=logout_url) elif method == 'insertmatch': match_id = int(request.args.get('id', 0)) team_a = request.args.get('a', None) or None team_b = request.args.get('b', None) or None match_stage = request.args.get('s', None) or None match_date = request.args.get('d', None) or None score_a = request.args.get('sa', None) or None or None score_b = request.args.get('sb', None) or None extra_a = request.args.get('ea', None) or None extra_b = request.args.get('eb', None) or None penalty_a = request.args.get('pa', None) or None penalty_b = request.args.get('pb', None) or None matches = Match.query(Match.matchid == match_id).fetch() if len(matches) == 0: match = Match(matchid=match_id, date=datetime.strptime(match_date, "%d %B %Y %H:%M"), stage=match_stage, team_a=team_a, team_b=team_b, score_a=None, score_b=None, extra_a=None, extra_b=None, penalty_a=None, penalty_b=None) logging.info('insert attempt:%s' % str(match)) match.put() return render_template( 'admin.html', msg='Match between %s and %s has been inserted!' % (match.team_a, match.team_b), logout_url=logout_url) else: match = matches[0] if match_date: match.date = datetime.strptime(match_date, "%d %B %Y %H:%M") if match_stage: match.stage = match_stage if team_a: match.team_a = team_a if team_b: match.team_b = team_b if score_a: match.score_a = int(score_a) if score_b: match.score_b = int(score_b) if extra_a: match.extra_a = int(extra_a) if extra_b: match.extra_b = int(extra_b) if penalty_a: match.penalty_a = int(penalty_a) if penalty_b: match.penalty_b = int(penalty_b) logging.info('update attempt:%s' % str(match)) match.put() return render_template( 'admin.html', msg='Match between %s and %s has been updated!' % (match.team_a, match.team_b)) elif method == 'sendmail': match_id = int(request.args.get('id', 0)) subject = request.args.get('s', None) or None body = request.args.get('b', None) or None html = request.args.get('h', None) or None logging.info('sendmail attempt:%s' % str(match_id)) if match_id > 0: bets = Bet.query(Bet.bet_match_id == match_id).fetch() match = Match.query(Match.matchid == match_id).fetch()[0] addresses = [] [addresses.append(str(bet.useremail)) for bet in bets] target_address = ';'.join(addresses) #subject = "Match between %s and %s just started!" %(match.team_a, match.team_b) #body = "http://localhost:8080/#/my" #html = "<a href=\"http://localhost:8080/#/my\">My guess</a>" send_mail(target_address, subject, body, html) return render_template( 'admin.html', msg='Mail to %s with <%s> has succeeded!' % (target_address, subject)) return render_template('admin.html', msg='You have to specify match id!', logout_url=logout_url) return render_template('admin.html', logout_url=logout_url) else: return render_template('logout.html', logout_url=users.create_logout_url( request.path), login_url=users.create_login_url(request.path))