Exemple #1
0
def fromXML(xml):
  game = Game()
  
  # exhibition games not supported
  if Util.XPathSelectOne(xml, "./@game_type") == "E":
    return
  
  game.home_team = TeamList.findById(Util.XPathSelectOne(xml,"./@home_team_id"))
  game.away_team = TeamList.findById(Util.XPathSelectOne(xml,"./@away_team_id"))
  
  game.event_id = Util.XPathSelectOne(xml,"game_media/media/@calendar_event_id")
  game.time = Util.XPathSelectOne(xml, "./@time") + ("AM" if Util.XPathSelectOne(xml, "./@ampm").upper() == "AM" else "PM") + " " + Util.XPathSelectOne(xml, "./@time_zone")
  
  game.status.update({
    "indicator": Util.XPathSelectOne(xml,"status/@ind"),
    "label": Util.XPathSelectOne(xml,"status/@status"),
    "reason": Util.XPathSelectOne(xml,"status/@reason"),
    "inning": Util.XPathSelectOne(xml,"status/@inning"),
    "half": ("top" if Util.XPathSelectOne(xml,"status/@top_inning") == "Y" else "bot")
  })
  
  on_base = Util.XPathSelectOne(xml, "runners_on_base/@status") or 0
  game.situation.update({
    # on base status is a bitfield.  count how many of the first 3 bits are set.
    "baserunners": sum([((int(on_base) & 7) >> bit) & 1 for bit in range(3)]),
    "outs": Util.XPathSelectOne(xml,"./@o")
  })
  
  for inning in xml.xpath('linescore/inning'):
    game.home_line["innings"] += (Util.XPathSelectOne(inning, "./@home") or "")
    game.away_line["innings"] += (Util.XPathSelectOne(inning, "./@away") or "")
  for stat in ["runs", "hits", "errors"]:
    game.home_line[stat] = Util.XPathSelectOne(xml,"linescore/" + stat[0] + "/@home")
    game.away_line[stat] = Util.XPathSelectOne(xml,"linescore/" + stat[0] + "/@away")
  
  for player, stats in [
    ["home_probable_pitcher", ["era", "wins", "losses"]],
    ["away_probable_pitcher", ["era", "wins", "losses"]],
    ["batter", ["h", "ab", "avg", "rbi", "hr"]],
    ["pitcher", ["ip", "er", "wins", "losses", "era"]],
    ["winning_pitcher", ["era", "wins", "losses"]],
    ["losing_pitcher", ["era", "wins", "losses"]],
    ["save_pitcher", ["era", "wins", "losses", "saves"]]
  ]:
    if Util.XPathSelectOne(xml, player + '/@id'):
      game.players[player] = {
        "name": Util.XPathSelectOne(xml, player + '/@first') + " " + Util.XPathSelectOne(xml, player + '/@last')
      }
      for stat in stats:
        game.players[player][stat] = Util.XPathSelectOne(xml, player + '/@' + stat)
  
  return game
    def AddFavoriteTeamShortcut(self):
        """
    A shortcut to watching your favorite team's video stream
    """
        team = TeamList.favoriteTeam()
        game = None
        stream = None

        if team:
            kwargs = {
                "title":
                C["FAVORITE_MARKER"] + "Watch the " + team.name + " Game",
                "thumb": R('logo-' + team.abbrev + '.png')
            }
            try:
                game = (game for game in getDailyGames()
                        if game.isFavorite()).next()
                if not game:
                    self.AddMessage(
                        "It looks like the " + team.name +
                        " aren't playing today.", **kwargs)
                else:
                    stream = game.streams.getBest()
                    kwargs = {
                        "title":
                        C["FAVORITE_MARKER"] +
                        ("Listen to" if stream.kind == "audio" else "Watch") +
                        " the " + team.name + " Game",
                        "thumb":
                        R('logo-' + team.abbrev + '.png')
                    }
                    if stream.pending:
                        if game.isFinal():
                            self.AddMessage(
                                "The game has ended, but the archived stream isn't available yet.",
                                header="Stream Not Available",
                                **kwargs)
                        else:
                            self.AddMessage("The " + team.name +
                                            " stream isn't available yet.",
                                            header="Stream Not Available",
                                            **kwargs)
                    else:
                        video_url = C["URL"]["PLAYER"] + "?" + urllib.urlencode(
                            {
                                'calendar_event_id': game.event_id,
                                'content_id': stream.id if stream.id else "",
                                'source': 'MLB'
                            })
                        self.Append(WebVideoItem(video_url, **kwargs))
                return
            except:
                self.AddMessage("Try looking in the \"Today's Games\" menu.",
                                header="Error Loading Stream",
                                **kwargs)
 def __init__(self, sender, submenu=None):
   """
   List teams, displaying the 'submenu' Menu when selected.
   """
   ABCMenu.__init__(self, title2=sender.itemTitle)
   
   favoriteteam = TeamList.favoriteTeam()
   if favoriteteam:
     self.AddMenu(submenu, C["FAVORITE_MARKER"] + favoriteteam.fullName(), dict(thumb=R('logo-' + favoriteteam.abbrev + '.png')), teamId=favoriteteam.id)
   
   for team in TeamList.teams:
     if not favoriteteam or favoriteteam != team:
       self.AddMenu(submenu, team.fullName(), dict(thumb=R('logo-' + team.abbrev + '.png')), teamId=team.id)
Exemple #4
0
 def __init__(self, sender, submenu=None):
   """
   List teams, displaying the 'submenu' Menu when selected.
   """
   ABCMenu.__init__(self, title2=sender.itemTitle)
   
   favoriteteam = TeamList.findByFullName(Prefs.Get('team'))
   if favoriteteam:
     self.AddMenu(submenu, C["FAVORITE_MARKER"] + favoriteteam.fullName(), teamId=favoriteteam.id)
   
   for team in TeamList.teams:
     if not favoriteteam or favoriteteam != team:
       self.AddMenu(submenu, team.fullName(), teamId=team.id)
Exemple #5
0
def CreatePrefs():
    Prefs.Add('team',
              type='enum',
              default='(None)',
              label='Favorite Team',
              values=TeamList.toOptions())
    Prefs.Add('login', type='text', default='', label='MLB.com Login')
    Prefs.Add('password',
              type='text',
              default='',
              label='MLB.com Password',
              option='hidden')
    Prefs.Add('allowspoilers',
              type='bool',
              default=True,
              label='Show spoilers for in-progress and completed games')
    def __init__(self, sender, submenu=None):
        """
    List teams, displaying the 'submenu' Menu when selected.
    """
        ABCMenu.__init__(self, title2=sender.itemTitle)

        favoriteteam = TeamList.favoriteTeam()
        if favoriteteam:
            self.AddMenu(submenu,
                         C["FAVORITE_MARKER"] + favoriteteam.fullName(),
                         dict(thumb=R('logo-' + favoriteteam.abbrev + '.png')),
                         teamId=favoriteteam.id)

        for team in TeamList.teams:
            if not favoriteteam or favoriteteam != team:
                self.AddMenu(submenu,
                             team.fullName(),
                             dict(thumb=R('logo-' + team.abbrev + '.png')),
                             teamId=team.id)
 def AddFavoriteTeamShortcut(self):
   """
   A shortcut to watching your favorite team's video stream
   """
   team = TeamList.favoriteTeam()
   game = None
   stream = None
   
   if team:
     kwargs = {
       "title": C["FAVORITE_MARKER"] + "Watch the " + team.name + " Game",
       "thumb": R('logo-' + team.abbrev + '.png')
     }      
     try:
       game = (game for game in getDailyGames() if game.isFavorite()).next()
       if not game:
         self.AddMessage("It looks like the " + team.name + " aren't playing today.", **kwargs)
       else:
         stream = game.streams.getBest()
         kwargs = {
           "title": C["FAVORITE_MARKER"] + ("Listen to" if stream.kind == "audio" else "Watch") + " the " + team.name + " Game",
           "thumb": R('logo-' + team.abbrev + '.png')
         }
         if stream.pending:
           if game.isFinal():
             self.AddMessage("The game has ended, but the archived stream isn't available yet.", header="Stream Not Available", **kwargs)
           else:
             self.AddMessage("The " + team.name + " stream isn't available yet.", header="Stream Not Available", **kwargs)
         else:
           video_url = C["URL"]["PLAYER"] + "?" + urllib.urlencode({
             'calendar_event_id': game.event_id,
             'content_id': stream.id if stream.id else "",
             'source': 'MLB'
           })
           self.Append(WebVideoItem(video_url, **kwargs))
       return
     except:
       self.AddMessage("Try looking in the \"Today's Games\" menu.", header="Error Loading Stream", **kwargs)
Exemple #8
0
def CreatePrefs():
  Prefs.Add('team', type='enum', default='(None)', label='Favorite Team', values=TeamList.toOptions())
  Prefs.Add('login', type='text', default='', label='MLB.com Login')
  Prefs.Add('password', type='text', default='', label='MLB.com Password', option='hidden')
  Prefs.Add('allowspoilers', type='bool', default=True, label='Show spoilers for in-progress and completed games')
Exemple #9
0
def fromXML(xml):
    game = Game()

    # exhibition games not supported
    if Util.XPathSelectOne(xml, "./@game_type") == "E":
        return

    game.home_team = TeamList.findById(
        Util.XPathSelectOne(xml, "./@home_team_id"))
    game.away_team = TeamList.findById(
        Util.XPathSelectOne(xml, "./@away_team_id"))

    game.event_id = Util.XPathSelectOne(xml,
                                        "game_media/media/@calendar_event_id")
    game.time = Util.XPathSelectOne(xml, "./@time") + (
        "AM" if Util.XPathSelectOne(xml, "./@ampm").upper() == "AM" else
        "PM") + " " + Util.XPathSelectOne(xml, "./@time_zone")

    game.status.update({
        "indicator":
        Util.XPathSelectOne(xml, "status/@ind"),
        "label":
        Util.XPathSelectOne(xml, "status/@status"),
        "reason":
        Util.XPathSelectOne(xml, "status/@reason"),
        "inning":
        Util.XPathSelectOne(xml, "status/@inning"),
        "half": ("top" if Util.XPathSelectOne(xml, "status/@top_inning") == "Y"
                 else "bot")
    })

    on_base = Util.XPathSelectOne(xml, "runners_on_base/@status") or 0
    game.situation.update({
        # on base status is a bitfield.  count how many of the first 3 bits are set.
        "baserunners":
        sum([((int(on_base) & 7) >> bit) & 1 for bit in range(3)]),
        "outs":
        Util.XPathSelectOne(xml, "./@o")
    })

    for inning in xml.xpath('linescore/inning'):
        game.home_line["innings"] += (Util.XPathSelectOne(inning, "./@home")
                                      or "")
        game.away_line["innings"] += (Util.XPathSelectOne(inning, "./@away")
                                      or "")
    for stat in ["runs", "hits", "errors"]:
        game.home_line[stat] = Util.XPathSelectOne(
            xml, "linescore/" + stat[0] + "/@home")
        game.away_line[stat] = Util.XPathSelectOne(
            xml, "linescore/" + stat[0] + "/@away")

    for player, stats in [["home_probable_pitcher", ["era", "wins", "losses"]],
                          ["away_probable_pitcher", ["era", "wins", "losses"]],
                          ["batter", ["h", "ab", "avg", "rbi", "hr"]],
                          ["pitcher", ["ip", "er", "wins", "losses", "era"]],
                          ["winning_pitcher", ["era", "wins", "losses"]],
                          ["losing_pitcher", ["era", "wins", "losses"]],
                          ["save_pitcher", ["era", "wins", "losses",
                                            "saves"]]]:
        if Util.XPathSelectOne(xml, player + '/@id'):
            game.players[player] = {
                "name":
                Util.XPathSelectOne(xml, player + '/@first') + " " +
                Util.XPathSelectOne(xml, player + '/@last')
            }
            for stat in stats:
                game.players[player][stat] = Util.XPathSelectOne(
                    xml, player + '/@' + stat)

    return game