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)
    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)
 def last_id(cls, next_id=None):
     if next_id is None:
         return Config.instance().last_id
     Config.instance().last_id = next_id