예제 #1
0
 def last_update(self, toDate, session=None):
     try:
         dbData = session.query(CacheDB.LastUpdate).filter_by(provider=self.providerID).one()
         dbData.time = int(time.mktime(toDate.timetuple()))
     except orm.exc.NoResultFound:
         session.add(CacheDB.LastUpdate(**{
             'provider': self.providerID,
             'time': int(time.mktime(toDate.timetuple()))
         }))
예제 #2
0
    def last_update(self, toDate):
        session = sickrage.app.cache_db.session()

        try:
            dbData = session.query(CacheDB.LastUpdate).filter_by(provider=self.providerID).one()
            dbData.time = int(time.mktime(toDate.timetuple()))
        except orm.exc.NoResultFound:
            session.add(CacheDB.LastUpdate(**{
                'provider': self.providerID,
                'time': int(time.mktime(toDate.timetuple()))
            }))
        finally:
            session.commit()
예제 #3
0
    def task(self, force=False):
        if self.running and not force:
            return

        try:
            self.running = True

            # set thread name
            threading.currentThread().setName(self.name)

            session = sickrage.app.cache_db.session()

            update_timestamp = int(
                time.mktime(datetime.datetime.now().timetuple()))

            try:
                dbData = session.query(
                    CacheDB.LastUpdate).filter_by(provider='theTVDB').one()
                last_update = int(dbData.time)
            except orm.exc.NoResultFound:
                last_update = update_timestamp
                dbData = CacheDB.LastUpdate(**{
                    'provider': 'theTVDB',
                    'time': 0
                })
                session.add(dbData)
            finally:
                session.commit()

            # get indexer updated show ids
            indexer_api = IndexerApi().indexer(
                **IndexerApi().api_params.copy())
            updated_shows = set(
                s["id"] for s in indexer_api.updated(last_update) or {})

            # start update process
            pi_list = []
            for show_obj in get_show_list():
                if show_obj.paused:
                    sickrage.app.log.info(
                        'Show update skipped, show: {} is paused.'.format(
                            show_obj.name))
                    continue

                if show_obj.status == 'Ended':
                    if not sickrage.app.config.showupdate_stale:
                        sickrage.app.log.info(
                            'Show update skipped, show: {} status is ended.'.
                            format(show_obj.name))
                        continue
                    elif not (datetime.datetime.now() -
                              datetime.datetime.fromordinal(
                                  show_obj.last_update)).days >= 90:
                        sickrage.app.log.info(
                            'Show update skipped, show: {} status is ended and recently updated.'
                            .format(show_obj.name))
                        continue

                try:
                    if show_obj.indexer_id in updated_shows:
                        pi_list.append(
                            sickrage.app.show_queue.update_show(
                                show_obj.indexer_id,
                                indexer_update_only=True,
                                force=False))
                    elif (datetime.datetime.now() -
                          datetime.datetime.fromordinal(
                              show_obj.last_update)).days >= 7:
                        pi_list.append(
                            sickrage.app.show_queue.update_show(
                                show_obj.indexer_id, force=False))
                except (CantUpdateShowException,
                        CantRefreshShowException) as e:
                    sickrage.app.log.debug(
                        "Automatic update failed: {}".format(e))

            ProgressIndicators.setIndicator(
                'dailyShowUpdates',
                QueueProgressIndicator("Daily Show Updates", pi_list))

            dbData.time = update_timestamp
            session.commit()
        finally:
            self.running = False