Example #1
0
def token():
    """
    Returns the current oauth token and its expiration date.
    """

    click.echo("Token: {}".format(Panoptes.client().get_bearer_token()))
    click.echo("Expiry time: {}".format(Panoptes.client().bearer_expires))
Example #2
0
def info(user_id, email, login):
    """
    Displays information about a user. Defaults to the current user if no ID or
    search criteria are given.
    """

    if (user_id and email) or (user_id and login) or (email and login):
        click.echo(
            'Error: At most only one of user ID, login, or email may be '
            'specified.',
            err=True,
        )
        return -1
    if user_id:
        user = User.find(user_id)
    elif email:
        try:
            user = next(User.where(email=email))
        except StopIteration:
            user = None
        if getattr(user, 'email', '') != email:
            click.echo('User not found', err=True)
            return -1
    else:
        if not login:
            login = Panoptes.client().username
        try:
            user = next(User.where(login=login))
        except StopIteration:
            user = None
        if getattr(user, 'login', '') != login:
            click.echo('User not found', err=True)
            return -1
    click.echo(yaml.dump(user.raw))
 def __init__(self, username, password):
     Panoptes.connect(username=username, password=password)
     token = Panoptes.client().get_bearer_token()
     self.headers = {'authorization': "Bearer %s" % token}
     self.session = requests.Session()