def new(name, project, workflow, last_id, caesar_name, sqs_queue,
        staging, auth_mode):
    """
    Generate new configuration for a project.

    \b
    Arguments
    ---------
    name - Arbitrary name used to store configuration
    project - Zooniverse project id
    workflow - Zooniverse workflow id
    """

    kwargs = {
        'name': name,
        'project': project,
        'workflow': workflow,
        'last_id': last_id,
        'sqs_queue' : sqs_queue,
        'staging_mode' : staging,
    }

    if auth_mode == 'api_key':
        kwargs.update({
            'client_id': os.environ.get('PANOPTES_CLIENT_ID'),
            'client_secret': os.environ.get('PANOPTES_CLIENT_SECRET')
        })

    if caesar_name is not None:
        kwargs.update({'caesar_name': caesar_name})

    config = Config(**kwargs)
    config.save()
Beispiel #2
0
 def __init__(self):
     logger.info('Authenticating with Caesar...')
     # self.pan = pan.Panoptes(login='******', endpoint=Config._config.login_endpoint())
     self.pan = pan.Panoptes.connect(
         client_secret=Config.client_secret(),
         client_id=Config.client_id(),
         redirect_url=Config.oauth_redirect_url(),
         endpoint=Config.login_endpoint())
     print('Panoptes Connection => {}'.format(self.pan))
 def get_classifications(cls, last_id=None):
     logger.debug('Getting classifications\n{}\n{}'.format(
         last_id,
         Config.instance().sqs_queue))
     if Config.instance().sqs_queue is not None:
         return SQSExtractor.get_classifications(
             Config.instance().sqs_queue)
     else:
         return StandardExtractor.get_classifications(last_id)
Beispiel #4
0
def new(name, project, workflow, last_id, caesar_name, sqs_queue=None, staging_mode=False, client_id=None, client_secret=None):
    kwargs = {
        'name': name,
        'project': project,
        'workflow': workflow,
        'last_id': last_id,
        'sqs_queue' : sqs_queue,
        'staging_mode' : staging_mode,
        'client_id' : client_id,
        'client_secret' : client_secret
    }
    if caesar_name is not None:
        kwargs.update({'caesar_name': caesar_name})

    config = Config(**kwargs)
    config.save()
    def get_classifications(cls, last_id):
        logger.debug('Getting classifications from Panoptes')
        project = Config.instance().project
        for c in Client.extract(project, last_id):
            cl = {
                'id': int(c.id),
                'subject': int(c.links.subjects[0].id),
                'project': int(c.links.project.id),
                'workflow': int(c.raw['links']['workflow']),
                'annotations': c.annotations,
            }

            if cl['workflow'] != Config.instance().workflow:
                continue

            if 'user' in c.raw['links']:
                cl.update({'user': c.raw['links']['user']})
            else:
                session = c.raw['metadata']['session'][:10]
                cl.update({'user': '******' % session})

            yield cl
    def get_classifications(cls, queue_url):
        # TODO: is there any way to use last_id?
        logger.debug('Getting classifications from SQS')
        project = Config.instance().project
        for c in SQSClient.extract(queue_url):
            cl = {
                'id': int(c['id']),
                'subject': int(c['subject_id']),
                'project': int(c['data']['classification']['project_id']),
                'workflow': c['data']['classification']['workflow_id'],
                'annotations': c['data']['classification']['annotations'],
                'user': c['data']['classification'][
                    'user_id']  # Assumes that extractor will handle user ID
            }

            yield cl
    def __init__(self):
        logger.info('Authenticating with Caesar...')
        config = Config.instance()
        kwargs = {
            'endpoint': config.login_endpoint(),
        }

        if config.auth_mode == 'api_key':
            kwargs.update({
                'client_id': config.client_id,
                'client_secret': config.client_secret,
            })
        elif config.auth_mode == 'interactive':
            kwargs.update({
                'login': '******',
            })
        elif config.auth_mode == 'environment':
            # panoptes client will handle getting environment variables
            # for authentication.
            # keeping this here for clarity
            pass

        self.pan = pan.Panoptes(**kwargs)
Beispiel #8
0
def load(name):
    config = Config.load(name)

    code.interact(local={**globals(), **locals()})
 def last_id(cls, next_id=None):
     if next_id is None:
         return Config.instance().last_id
     Config.instance().last_id = next_id