def get(self): ''' game id ''' gid = self.request.get('gid') ''' derive year/month/day from the game id ''' year = gid[:4] month = gid[5:7] day = gid[8:10] ''' determine dates for links based on date selected ''' selDay = date(int(year), int(month), int(day)) prevDay = selDay - timedelta(days=1) nextDay = selDay + timedelta(days=1) masterScoreboardDOM = xml_helper.fetchMasterScoreboard(year, month, day) gamesNode = masterScoreboardDOM.getElementsByTagName("games")[0] gameday = xml_helper.buildGameDay(gamesNode) games = [] game = {} boxscore = {} for node in gamesNode.childNodes: if node.nodeType == node.ELEMENT_NODE: game = xml_helper.buildGame(node) if gid == game.gameday: selectedGame = xml_helper.buildGame(node) boxscoreDOM = xml_helper.fetchBoxscore(gameday.year, gameday.month, gameday.day, game.gameday) if boxscoreDOM is None: boxscore = {} else: boxscoreNode = boxscoreDOM.getElementsByTagName("boxscore")[0] boxscore = xml_helper.buildBoxscore(boxscoreNode) games.append(game) template = "boxscore.html" template_values = { 'gid': gid, 'gameday': gameday, 'games': games, 'game': selectedGame, 'boxscore': boxscore, 'prevDay': prevDay, 'selDay': selDay, 'nextDay': nextDay } self.generate(template, template_values)
def get(self): # manipulate current date to supply to XML fetch today = datetime.today() - timedelta(hours=5) month = str(today.month) day = str(today.day) if today.month < 10: month = "0" + str(today.month) if today.day < 10: day = "0" + str(today.day) # if user is logged in, retrieve preferences q = Preferences.gql("WHERE user = :1", users.get_current_user()) results = q.fetch(1) teamsToTrack = [] for p in results: teamsToTrack = p.teamsToTrack # get standings standings = standings_helper.getStandings(today.year, today.month, today.day) # retrieve xml for the day's scoreboard masterScoreboardDOM = xml_helper.fetchMasterScoreboard(str(today.year), month, day) template_values = { 'selDay': today, 'selDayStr': today.strftime("%B %d, %Y"), 'teamsToTrack': teamsToTrack, 'standings': standings } if masterScoreboardDOM is None: template = "no-games-today.html" else: gamesNode = masterScoreboardDOM.getElementsByTagName("games")[0] if gamesNode.childNodes.length == 0: template = "no-games-today.html" else: template = "scoreboard.html" # build the day's GameDay object gameday = xml_helper.buildGameDay(gamesNode) gameday.yesterday_date = date(int(gameday.year), int(gameday.month), int(gameday.day)) - timedelta(days=1) # build an array of the day's games games = [] for node in gamesNode.childNodes: if node.nodeType == node.ELEMENT_NODE: games.append(xml_helper.buildGame(node)) template_values['gameday'] = gameday template_values['games'] = games self.generate(template, template_values)
def get(self): # Process request data. year = self.request.get('year') month = self.request.get('month') day = self.request.get('day') if len(month) == 1: month = "0" + month if len(day) == 1: day = "0" + day # build selected date selDay = date(int(year), int(month), int(day)) prevDay = selDay - timedelta(days=1) nextDay = selDay + timedelta(days=1) # get standings standings = standings_helper.getStandings(selDay.year, selDay.month, selDay.day) template_values = { 'prevDay': prevDay, 'selDay': selDay, 'nextDay': nextDay, 'selDayStr': selDay.strftime("%B %d, %Y"), 'standings': standings } # retrieve xml for the day's scoreboard masterScoreboardDOM = xml_helper.fetchMasterScoreboard(year, month, day) if masterScoreboardDOM is None: template = "no-games-today.html" else: gamesNode = masterScoreboardDOM.getElementsByTagName("games")[0] if gamesNode.childNodes.length == 0: template = "no-games-today.html" else: template = "scoreboard.html" # build the day's GameDay object gameday = xml_helper.buildGameDay(gamesNode) gameday.yesterday_date = date(int(gameday.year), int(gameday.month), int(gameday.day)) - timedelta(days=1) # build an array of the day's games games = [] for node in gamesNode.childNodes: if node.nodeType == node.ELEMENT_NODE: games.append(xml_helper.buildGame(node)) template_values['gameday'] = gameday template_values['games'] = games self.generate(template, template_values)
def get(self): refresh = self.request.get('r') if refresh != "on": refresh = "off"; refreshTime = self.request.get('t') if refreshTime == "": refreshTime = 60 ''' game id ''' gid = self.request.get('gid') ''' derive year/month/day from the game id ''' year = gid[:4] month = gid[5:7] day = gid[8:10] ''' determine dates for links based on date selected ''' selDay = date(int(year), int(month), int(day)) prevDay = selDay - timedelta(days=1) nextDay = selDay + timedelta(days=1) today = datetime.today() - timedelta(hours=5) lastUpdate = datetime.today() - timedelta(hours=5) masterScoreboardDOM = xml_helper.fetchMasterScoreboard(year, month, day) gamesNode = masterScoreboardDOM.getElementsByTagName("games")[0] gameday = xml_helper.buildGameDay(gamesNode) games = [] game = {} boxscore = {} highlights = {} innings = [] for node in gamesNode.childNodes: if node.nodeType == node.ELEMENT_NODE: game = xml_helper.buildGame(node) if gid == game.gameday: #selectedGame = xml_helper.buildGame(node) selectedGame = game boxscoreDOM = xml_helper.fetchBoxscore(gameday.year, gameday.month, gameday.day, game.gameday) boxscoreNode = boxscoreDOM.getElementsByTagName("boxscore")[0] boxscore = xml_helper.buildBoxscore(boxscoreNode) highlightsDOM = xml_helper_highlights.fetchHighlights(gameday.year, gameday.month, gameday.day, game.gameday) if highlightsDOM is not None: highlightsNode = highlightsDOM.getElementsByTagName("highlights")[0] highlights = xml_helper_highlights.buildHighlights(highlightsNode, gid) games.append(game) template_values = { 'gid': gid, 'gameday': gameday, 'games': games, 'game': selectedGame, 'boxscore': boxscore, 'highlights': highlights, 'lastUpdate': lastUpdate.strftime("%m/%d %I:%M:%S %p"), 'prevDay': prevDay, 'selDay': selDay, 'today': today, 'nextDay': nextDay } path = os.path.join(os.path.dirname(__file__), 'html/highlights.html') self.response.out.write(template.render(path, template_values))