Exemplo n.º 1
0
  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)
Exemplo n.º 2
0
  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)