def update_games(): # this is used to find the id within the href of the time element on the schedule find_str = 'games' link = "https://richmondskating.ezleagues.ezfacility.com/teams/2200008/Coach-Potatoes.aspx" request = requests.get(link) content = request.content soup = BeautifulSoup(content, "html.parser") schedule = soup.find("table", {"id": "ctl00_C_Schedule1_GridView1"}) schedule_rows = schedule.find_all( "tr", {"class": ["RowStyle", "AlternateRowStyle"]}) for sr in schedule_rows: game_info = sr.find_all("td") date = game_info[0].a.text home_team = game_info[1].a.text away_team = game_info[3].a.text time = game_info[4].a.text venue = game_info[5].a.text id = game_info[4].a['href'] # 8 digit number after "games/" is used as id for game slice_id = id[id.find(find_str) + 6:id.find(find_str) + 14] game = Database.find_one('games', {"_id": slice_id}) if game is None: new_game = Game(date, time, venue, home_team, away_team, slice_id) new_game.save_to_mongo() Attendance.build_for_new_game(new_game._id) else: game = Game.get_game_by_id(slice_id) game.date = date game.home_team = home_team game.away_team = away_team game.time = time game.venue = venue game.save_to_mongo()
def create_game(): if request.method == 'POST': new_game = Game(game_num=request.form['game_num'], away_team=request.form['away_team'], home_team=request.form['home_team'], year=request.form['year'], location=Location.get_location_by_id( request.form['location']).json(), stadium=request.form['stadium'], date=datetime.strptime(request.form['date'], "%m/%d/%Y")) new_game.save_to_mongo() users = User.get_all_users() if new_game.location.city == 'Blacksburg': attendance = 'Yes' else: attendance = 'No' for u in users: UserGame(user=u.json(), game=new_game._id, attendance=attendance, game_date=None, home_score=0, away_score=0).save_to_mongo() years = Year.get_all_years() teams = Team.get_teams() locations = Location.get_all_locations() stadiums = Game.get_all_stadiums() stadiums.sort() return render_template("games/create_game.jinja2", teams=teams, locations=locations, stadiums=stadiums, years=years)