How to use the flexget.manager.Session function in FlexGet

To help you get started, we’ve selected a few FlexGet examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Flexget / Flexget / tests / test_secrets.py View on Github external
def test_secret_from_db(self, execute_task, manager):
        with Session() as session:
            s = Secrets(secrets={'test_secret_db': True})
            session.add(s)

        fire_event('manager.before_config_validate', manager.config, manager)

        task = execute_task('test_secret_from_db')
        assert len(task.accepted) == 1
github Flexget / Flexget / flexget / plugins / filter / imdb_queue.py View on Github external
def queue_add(self, title=None, imdb_id=None, quality='ANY', force=True):
        """Add an item to the queue with the specified quality"""

        if not title or not imdb_id:
            # We don't have all the info we need to add movie, do a lookup for more info
            result = self.parse_what(imdb_id or title)
            title = result['title']
            imdb_id = result['imdb_id']
        quality = self.validate_quality(quality)

        session = Session()

        # check if the item is already queued
        item = session.query(ImdbQueue).filter(ImdbQueue.imdb_id == imdb_id).first()
        if not item:
            item = ImdbQueue(imdb_id, quality, force)
            item.title = title
            session.add(item)
            session.commit()
            return {'title': title, 'imdb_id': imdb_id, 'quality': quality, 'force': force}
        else:
            raise QueueError('ERROR: %s is already in the queue' % title)
github Flexget / Flexget / flexget / components / history / cli.py View on Github external
def do_cli(manager, options):
    with Session() as session:
        query = session.query(db.History)
        if options.search:
            search_term = options.search.replace(' ', '%').replace('.', '%')
            query = query.filter(db.History.title.like('%' + search_term + '%'))
        if options.task:
            query = query.filter(db.History.task.like('%' + options.task + '%'))
        query = query.order_by(desc(db.History.time)).limit(options.limit)
        table_data = []
        if options.short:
            table_data.append(['Time', 'Title'])
        for item in reversed(query.all()):
            if not options.short:
                table_data.append(['Task', item.task])
                table_data.append(['Title', item.title])
                table_data.append(['URL', item.url])
                table_data.append(['Time', item.time.strftime("%c")])
github Flexget / Flexget / flexget / plugins / list / pending_list.py View on Github external
def discard(self, entry):
        with Session() as session:
            db_entry = self._entry_query(session=session, entry=entry)
            if db_entry:
                log.debug('deleting entry %s', db_entry)
                session.delete(db_entry)
github Flexget / Flexget / flexget / components / series / series.py View on Github external
def on_task_start(self, task, config):
        # Only operate if task changed
        if not task.config_modified:
            return

        # Clear all series from this task
        with Session() as session:
            add_series_tasks = {}

            session.query(db.SeriesTask).filter(db.SeriesTask.name == task.name).delete()
            if not task.config.get('series'):
                return
            config = self.prepare_config(task.config['series'])

            # Prefetch series
            names = [str(list(series.keys())[0]) for series in config]
            existing_series = (
                session.query(db.Series)
                .filter(db.Series.name.in_(names))
                .options(joinedload('alternate_names'))
                .all()
            )
            existing_series_map = dict([(s.name_normalized, s) for s in existing_series])
github Flexget / Flexget / flexget / components / variables / variables.py View on Github external
def variables_to_db(variables_dict):
    with Session() as session:
        variables = session.query(Variables).first()
        if not variables:
            variables = Variables()
        variables.variables = variables_dict
        session.merge(variables)
github Flexget / Flexget / flexget / plugins / filter / pending_approval.py View on Github external
def on_task_input(self, task, config):
        if not config:
            return

        approved_entries = []
        with Session() as session:
            for approved_entry in session.query(PendingEntry) \
                    .filter(PendingEntry.task_name == task.name) \
                    .filter(PendingEntry.approved == True) \
                    .all():
                e = approved_entry.entry
                e['approved'] = True
                e['immortal'] = True
                approved_entries.append(e)

        return approved_entries
github Flexget / Flexget / flexget / plugins / filter / retry_failed.py View on Github external
def add_failed(self, entry, reason=None, config=None, **kwargs):
        """Adds entry to internal failed list, displayed with --failed"""
        # Make sure reason is a string, in case it is set to an exception instance
        reason = str(reason) or 'Unknown'
        with Session() as session:
            # query item's existence
            item = session.query(FailedEntry).filter(FailedEntry.title == entry['title']). \
                filter(FailedEntry.url == entry['original_url']).first()
            if not item:
                item = FailedEntry(entry['title'], entry['original_url'], reason)
                item.count = 0
            if item.count > FAIL_LIMIT:
                log.error('entry with title \'%s\' has failed over %s times', entry['title'], FAIL_LIMIT)
                return
            retry_time = self.retry_time(item.count, config)
            item.retry_time = datetime.now() + retry_time
            item.count += 1
            item.tof = datetime.now()
            item.reason = reason
            session.merge(item)
            log.debug('Marking %s in failed list. Has failed %s times.', item.title, item.count, )
github Flexget / Flexget / flexget / plugins / filter / seen.py View on Github external
@event('forget')
def forget(value):
    """
    See module docstring
    :param string value: Can be task name, entry title or field value
    :return: count, field_count where count is number of entries removed and field_count number of fields
    """
    with Session() as session:
        log.debug('forget called with %s', value)
        count = 0
        field_count = 0
        for se in session.query(SeenEntry).filter(or_(SeenEntry.title == value, SeenEntry.task == value)).all():
            field_count += len(se.fields)
            count += 1
            log.debug('forgetting %s', se)
            session.delete(se)

        for sf in session.query(SeenField).filter(SeenField.value == value).all():
            se = session.query(SeenEntry).filter(SeenEntry.id == sf.seen_entry_id).first()
            field_count += len(se.fields)
            count += 1
            log.debug('forgetting %s', se)
            session.delete(se)
    return count, field_count
github Flexget / Flexget / flexget / components / sites / sites / morethantv.py View on Github external
'username': username,
                    'password': password,
                    'login': 'Log in',
                    'keeplogged': '1',
                },
                timeout=30,
            )
        except RequestException as e:
            raise plugin.PluginError('MoreThanTV login failed: %s' % e)

        if 'Your username or password was incorrect.' in response.text:
            raise plugin.PluginError(
                'MoreThanTV login failed: Your username or password was incorrect.'
            )

        with Session() as session:
            expires = None
            for c in requests.cookies:
                if c.name == 'session':
                    expires = c.expires
            if expires:
                expires = datetime.datetime.fromtimestamp(expires)
            log.debug('Saving or updating MoreThanTV cookie in db')
            cookie = MoreThanTVCookie(
                username=username, cookie=dict(requests.cookies), expires=expires
            )
            session.merge(cookie)
            return cookie.cookie