示例#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 ) )
 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 ) )
示例#3
0
 def titleRefresh(self,mysched=None):
     self.player = int(self.mycfg.get('player_id'))
     if len(self.data) == 0:
         titlestr = "STATS NOT AVAILABLE"
     else:
         try:
             upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S-04:00")
         except:
             upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S")
         gametime=MLBGameTime(upd,self.mycfg.get('time_offset'))
         update_datetime = gametime.localize()
         update_str = update_datetime.strftime('%Y-%m-%d %H:%M:%S')
         self.type = self.mycfg.get('stat_type')
         type = self.type.upper()
         sort = self.mycfg.get('sort_column').upper()
         order = STATS_SORT_ORDER[int(self.mycfg.get('sort_order'))].upper()
         team =  int(self.mycfg.get('sort_team'))
         if team > 0:
             league_str = STATS_TEAMS[team].upper()
         else:
             league_str = self.mycfg.get('league')
         
         titlestr = "%s STATS (%s:%s) SORT ORDER: %s" % ( type, league_str, 
                                                          sort, order )
         if self.player > 0:
             titlestr = "PLAYER: %s"%self.mycfg.get('player_name')
             ( y, m, d ) = self.data[-1]['birthdate']
             # this part is dumb because datetime doesn't support year<1900
             # but still want localized name of month
             now=datetime.now()
             birthdate=now.replace(month=m, day=d)
             titlestr += " (Born: " + birthdate.strftime('%b %d, ') + str(y) 
             if self.data[-1]['deathdate'] is not None:
                 ( y, m, d ) = self.data[-1]['deathdate']
                 deathdate=now.replace(month=m, day=d)
                 titlestr += " Died: " + deathdate.strftime('%b %d, ') + str(y)
             titlestr += ")"
                 
     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.season_type = self.mycfg.get('season_type')
     if self.player > 0:
         wid=2
     elif self.season_type == 'ALL':
         wid=1
     else:
         wid=0
     self.titlewin.addnstr(2,0,self.hdr[self.type][wid],curses.COLS-2,curses.A_BOLD)
     self.titlewin.refresh()
示例#4
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()
示例#5
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
示例#6
0
 def titleRefresh(self,mysched=None):
     self.player = int(self.mycfg.get('player_id'))
     if len(self.data) == 0:
         titlestr = "STATS NOT AVAILABLE"
     else:
         try:
             upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S-04:00")
         except:
             upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S")
         gametime=MLBGameTime(upd,self.mycfg.get('time_offset'))
         update_datetime = gametime.localize()
         update_str = update_datetime.strftime('%Y-%m-%d %H:%M:%S')
         self.type = self.mycfg.get('stat_type')
         type = self.type.upper()
         sort = self.mycfg.get('sort_column').upper()
         order = STATS_SORT_ORDER[int(self.mycfg.get('sort_order'))].upper()
         team =  int(self.mycfg.get('sort_team'))
         if team > 0:
             league_str = STATS_TEAMS[team].upper()
         else:
             league_str = self.mycfg.get('league')
         
         titlestr = "%s STATS (%s:%s) SORT ORDER: %s" % ( type, league_str, 
                                                          sort, order )
         if self.player > 0:
             titlestr = "CAREER STATS FOR: %s"%self.mycfg.get('player_name')
     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.season_type = self.mycfg.get('season_type')
     if self.player > 0:
         wid=2
     elif self.season_type == 'ALL':
         wid=1
     else:
         wid=0
     self.titlewin.addnstr(2,0,self.hdr[self.type][wid],curses.COLS-2,curses.A_BOLD)
     self.titlewin.refresh()
示例#7
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
示例#8
0
    def statusRefresh(self):
        n = self.current_cursor

        #upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S-04:00")
        try:
            upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S-04:00")
        except:
            upd = datetime.strptime(self.last_update, "%Y-%m-%dT%H:%M:%S")
        gametime=MLBGameTime(upd,self.mycfg.get('time_offset'))
        update_datetime = gametime.localize()
        update_str = update_datetime.strftime('%Y-%m-%d %H:%M:%S')
        status_str = "Last Updated: %s" % update_str
        if self.mycfg.get('season_type') == 'ANY':
            #season_str = "[%4s]" % update_datetime.year
            season_str = "[%4s]" % self.mycfg.get('season')
        else:
            if int(self.mycfg.get('active_sw')):
                season_str = "[ACTV]"
            else:
                season_str = "[ALL ]"
        if self.mycfg.get('curses_debug'):
            status_str = 'd_len=%s, r_len=%s, cc=%s, rc=%s, cl_-4: %s' %\
                ( str(len(self.data)), str(len(self.records)),
                  str(self.current_cursor), str(self.record_cursor),
                  str(curses.LINES-4) )

        padding = (curses.COLS-2)- (len(status_str) + len(season_str))
        status_str += ' '*padding + season_str
        # And write the status
        try:
            self.statuswin.addnstr(0,0,status_str,curses.COLS-2,curses.A_BOLD)
        except:
            rows = curses.LINES
            cols = curses.COLS
            slen = len(status_str)
            raise Exception,'(' + str(slen) + '/' + str(cols) + ',' + str(n) + '/' + str(rows) + ') ' + status_str
        self.statuswin.refresh()
示例#9
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