Пример #1
0
class StoreShell(object):
    def __init__(self):
        self.program_api = ProgramAPI()
        self.sess = get_session()
        self.logger = logging.getLogger('storeshell')

    def run(self):
        channels = self.get_channels()
        self.logger.info('found %d channel(s)' % len(channels))
        self.sess.add_all(channels)
        self.channels = channels
        self.sess.commit()

        self.store_programs()
        #self.remove_old_programs()

    def get_channels(self):
        return [self.dict_to_channel(ch) for ch in self.program_api.channels()]

    def store_programs(self):
        day = date.today()
        noresouce_count = 0
        while True:
            r = self.store_programs_day(day)
            if not r:
                break
            day += timedelta(days=1)

    def store_programs_day(self, day):
        num_programs = 0
        for channel in self.channels:
            self.logger.info('attempting to store programs: %s %s' % (day, channel))
            try:
                program_datas = self.program_api.programs(day, channel.cid)
            except APIError, e:
                self.logger.warn('An error occured: %s' % e)
            except NoResourceError:
                self.logger.info('NoResourceError: %s %s' % (day, channel))
            else:
Пример #2
0
 def __init__(self):
     self.program_api = ProgramAPI()
     self.sess = get_session()
     self.logger = logging.getLogger('storeshell')