示例#1
0
 def parsePreviewGameData(self,game):
     gid = game.keys()[0]
     status = game[gid]['status']
     status_str = status
     gametime=game[gid]['time']
     ampm=game[gid]['ampm']
     gt = datetime.datetime.strptime('%s %s'%(gametime, ampm),'%I:%M %p')
     now = datetime.datetime.now()
     gt = gt.replace(year=now.year, month=now.month, day=now.day)
     gametime=MLBGameTime(gt,self.mycfg.get('time_offset'))
     lt=gametime.localize()
     time_str = lt.strftime('%I:%M %p')
     away_str = ' AP: %s (%s-%s %s)' % \
                ( game[gid]['pitchers']['away_probable_pitcher'][1],
                  game[gid]['pitchers']['away_probable_pitcher'][2],
                  game[gid]['pitchers']['away_probable_pitcher'][3],
                  game[gid]['pitchers']['away_probable_pitcher'][4] )
     home_str = ' HP: %s (%s-%s %s)' % \
                ( game[gid]['pitchers']['home_probable_pitcher'][1],
                  game[gid]['pitchers']['home_probable_pitcher'][2],
                  game[gid]['pitchers']['home_probable_pitcher'][3],
                  game[gid]['pitchers']['home_probable_pitcher'][4] )
     self.data.append("%-13s %3s %3s%3s%3s %s" % \
             ( status_str, game[gid]['away_file_code'].upper(),
               0,
               0,
               0,
               away_str ) )
     self.data.append("%-13s %3s %3s%3s%3s %s" % \
             ( time_str, game[gid]['home_file_code'].upper(),
               0,
               0,
               0,
               home_str ) )
示例#2
0
 def titleRefresh(self,mysched):
     if len(self.stdata) == 0:
         titlestr = "STANDINGS NOT AVAILABLE"
     else:
         upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S-04:00")
         gametime=MLBGameTime(upd,self.mycfg.get('time_offset'))
         update_datetime = gametime.localize()
         update_str = update_datetime.strftime('%Y-%m-%d %H:%M:%S')
         titlestr = "STANDINGS: Last updated: %s" % update_str
         #titlestr += " (updates only once a day)"
     padding = curses.COLS - (len(titlestr) + 6)
     titlestr += ' '*padding
     pos = curses.COLS - 6
     self.titlewin.addstr(0,0,titlestr)
     self.titlewin.addstr(0,pos,'H', curses.A_BOLD)
     self.titlewin.addstr(0,pos+1, 'elp')
     self.titlewin.hline(1, 0, curses.ACS_HLINE, curses.COLS-1)
     self.titlewin.refresh()
示例#3
0
 def __scheduleFromJson(self):
     out = []
     gameinfo = dict()
     media = json.loads(self.__getSchedule().read())
     for game in media['data']['games']['game']:
         # TODO: For starters, ignore games without media, revisit this later
         if not game['game_media'].has_key('homebase'):
             continue
         id = game['id']
         gameinfo[id] = dict()
         for key in game.keys():
             gameinfo[id][key] = game[key]
         event_time = game['event_time']
         listdate=datetime.datetime.strptime('%s %s' %\
                                                ( event_time,self.ymd_str ),
                                                '%I:%M %p %Y%m%d')
         gametime = MLBGameTime(listdate, self.shift)
         localdate = gametime.localize()
         gameinfo[id]['local_datetime'] = localdate
         gameinfo[id]['event_time'] = localdate
         gameinfo[id]['local_time'] = localdate.strftime('%I:%M %p')
         # retaining all the old data elements until proven unnecessary
         #gameinfo[id]['time'] = game['event_time'].split()[0]
         #gameinfo[id]['ampm'] = game['event_time'].split()[1]
         home = game['home_team_id']
         away = game['away_team_id']
         if game['game_media'].has_key('homebase'):
             gameinfo[id]['content'] = self.parseMediaGrid(
                 game['game_media']['homebase']['media'], home, away)
         else:
             gameinfo[id]['content'] = []
         # update TEAMCODES dynamically
         for team in ('home', 'away'):
             teamcode = str(game['%s_code' % team])
             teamfilecode = str(game['%s_file_code' % team])
             if not TEAMCODES.has_key(teamcode):
                 TEAMCODES[teamcode] = (str(game['%s_team_id' % team]),
                                        '%s %s' %
                                        (str(game['%s_team_city' % team]),
                                         str(game['%s_team_name' % team])),
                                        teamfilecode)
         out.append(gameinfo[id])
     return out
示例#4
0
 def trimXmlList(self,blackout=()):
     # This is the XML version of trimList
     # easier to write a new method than adapt the old one
     if not self.data:
         self.error_str = "Listings data empty."
         raise MLBXmlError, self.error_str
     out = []
     for game in self.data:
         dct = {}
         dct['home'] = game['home_file_code']
         dct['away'] = game['away_file_code']
         dct['teams'] = {}
         dct['teams']['home'] = dct['home']
         dct['teams']['away'] = dct['away']
         dct['event_id'] = game['calendar_event_id']
         if dct['event_id'] == "":
              dct['event_id'] = None
         dct['ind']   = game['ind']
         try:
             dct['status'] = STATUSCODES[game['status']]
         except:
             dct['status'] = game['status'] 
         if game['status'] in ('In Progress','Preview','Delayed','Warm-up'):
             try:
                 game['content']['blackout']
             except:
                 # damn bogus WBC entries
                 game['content']['blackout'] = ""
             if game['content']['blackout'] == 'MLB_NATIONAL_BLACKOUT':
                 dct['status'] = 'NB'
         dct['gameid'] = game['id']
         # I'm parsing the time by hand because strptime
         # doesn't work on windows and only works on
         # python>=2.5. The time format is always going to
         # be the same, so might as well just take care of
         # it ourselves.
         time_string = game['time'].strip()
         ampm = game['ampm'].lower()
         hrs, mins = time_string.split(':')
         hrs = int(hrs) % 12
         try:
             mins = int(mins)
         except:
             raise Exception,repr(mins)
         if ampm == 'pm':
             hrs += 12
         # So that gives us the raw time, i.e., on the East
         # Coast. Not knowing about DST or anything else.
         raw_time = datetime.datetime(self.year, 
                                      self.month, 
                                      self.day, 
                                      hrs,
                                      mins)
         # And now we convert that to the user's local, or
         # chosen time zone.
         dct['start_time'] = raw_time.strftime('%H:%M:%S')
         #dct['event_time'] = gameTimeConvert(raw_time, self.shift)
         gametime = MLBGameTime(raw_time, self.shift)
         dct['event_time'] = gametime.localize()
         if not TEAMCODES.has_key(dct['away']):
             TEAMCODES[dct['away']] = TEAMCODES['unk']
         if not TEAMCODES.has_key(dct['home']):
             TEAMCODES[dct['home']] = TEAMCODES['unk']
         #raise Exception,repr(game)
         dct['video'] = {}
         for s in STREAM_SPEEDS:
             dct['video'][s] = []
         dct['video']['swarm'] = []
         dct['condensed'] = []
         #raise Exception,repr(game['content']['video'])
         speeds=list(STREAM_SPEEDS)
         speeds.append('swarm')
         for key in speeds:
             try:
                 dct['video'][key] = game['content']['video'][key]
             except KeyError:
                 dct['video'][key] = None
         dct['audio'] = []
         dct['alt_audio'] = []
         try:
             dct['audio'] = game['content']['audio']
         except KeyError:
             dct['audio'] = None
         try:
             dct['alt_audio'] = game['content']['alt_audio']
         except:
             dct['alt_audio'] = []
         try:
             dct['condensed'] = game['content']['condensed']
         except KeyError:
             dct['condensed'] = None
         if dct['condensed']:
             dct['status'] = 'CG'
         dct['media_state'] = game['media_state']
         dct['free'] = game['content']['free']
         out.append((dct['gameid'], dct))
     return out