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 _retrieve_user(user_id): if user_id in users: user = users[user_id] else: Panoptes.connect(endpoint=getenv('PANOPTES_URL', 'https://panoptes.zooniverse.org/'), client_id=getenv('PANOPTES_CLIENT_ID'), client_secret=getenv('PANOPTES_CLIENT_SECRET')) user = User.find(user_id) users[user_id] = user return user
def _retrieve_user(user_id): if user_id in users: user = users[user_id] else: try: user = User.find(user_id) except PanoptesAPIException: # some users are not found in panoptes # return an empty class with an `id` attribute user = CantFindUser(user_id) users[user_id] = user return user
def delete(force, user_ids): """ Deletes a user. Only works if you're an admin. """ for user_id in user_ids: user = User.find(user_id) if not force: click.confirm('Delete user {} ({})?'.format( user_id, user.login, ), abort=True) user.delete()
def _retrieve_user(user_id): if user_id in users: user = users[user_id] else: Panoptes.connect(endpoint=getenv('PANOPTES_URL', 'https://panoptes.zooniverse.org/'), client_id=getenv('PANOPTES_CLIENT_ID'), client_secret=getenv('PANOPTES_CLIENT_SECRET')) try: user = User.find(user_id) except PanoptesAPIException: # some users are not found in panoptes # return an empty class with an `id` attribute user = CantFindUser(user_id) users[user_id] = user return user
def get_credited_name_all(vols, whichtype='user_id'): x = panoptes_connect() disp_names = vols.copy() i_print = int(len(vols) / 10) if i_print > 1000: i_print = 1000 elif i_print < 10: i_print = 10 if whichtype == 'user_id': # user ID lookup has a different format for the query for i, the_id in enumerate(vols): user = User.find(int(the_id)) name_use = user.credited_name if name_use == '': name_use = user.display_name if name_use == '': name_use = user.login disp_names.loc[(vols == the_id)] = name_use #credited_names[the_id] = user.credited_name if i % i_print == 0: print("Credited name: lookup %d of %d (%s --> %s)" % (i, len(vols), the_id, name_use)) else: # if we're here we don't have user ID but presumably do have login for i, the_login in enumerate(vols): name_use = the_login for user in User.where(login=the_login): name_use = user.display_name #credited_names[the_login] = cname disp_names.loc[(vols == the_login)] = name_use if i % i_print == 0: print("Credited name: lookup %d of %d (%s --> %s)" % (i, len(vols), the_login, name_use)) return disp_names
def get_credited_name_all(vols, whichtype='user_id', verbosity=2): from panoptes_client import User # nevermind, we don't need this because credited names and usernames are public # from panoptes_connect import panoptes_connect # x = panoptes_connect() disp_names = vols.copy() i_print = int(len(vols) / 10) if i_print > 1000: i_print = 1000 elif i_print < 10: i_print = 10 # print("whichtype = %s" % whichtype) # we can look up the credited_name either via user_id or user_name # currently classification exports call it "user_name" and the Panoptes DB # calls it "login" missing_ids = [] if whichtype == 'user_id': # user ID lookup has a different format for the query # also it fails with an error instead of a 0-length array # so let's catch those but keep trying for i, the_id in enumerate(vols): id_ok = True try: user = User.find(int(the_id)) except Exception as e: id_ok = False print(e) missing_ids.append(int(the_id)) if id_ok: name_use = user.credited_name if name_use == '': name_use = user.display_name if name_use == '': name_use = user.login disp_names.loc[(vols == the_id)] = name_use #credited_names[the_id] = user.credited_name if i % i_print == 0: print("Credited name: lookup %d of %d (%s --> %s)" % (i, len(vols), the_id, name_use)) else: if i % i_print == 0: print( "Credited name: lookup %d of %d (%s --> ___MISSING_OR_ERROR___%d___)" % (i, len(vols), the_id, len(missing_ids))) else: # if we're here we don't have user ID but presumably do have login/username for i, the_login in enumerate(vols): name_use = the_login the_user = User.where(login=the_login) if the_user.object_count > 0: for user in the_user: try: name_use = user.credited_name except: name_use = user.display_name #credited_names[the_login] = cname disp_names.loc[(vols == the_login)] = name_use if i % i_print == 0: print("Credited name: lookup %d of %d (%s --> %s)" % (i, len(vols), the_login, name_use)) else: # the name lookup didn't work, so save it missing_ids.append(the_login) print(" WARNING: User not found: %s" % the_login) if i % i_print == 0: print( "Credited name: lookup %d of %d (%s --> ___MISSING_OR_ERROR___%d___)" % (i, len(vols), the_login, len(missing_ids))) if (len(missing_ids) > 0) & (verbosity > 0): print( " WARNING: id search turned up %d bad result(s), your list may be incomplete!" % len(missing_ids)) if verbosity >= 2: print(" Here are the ids it returned an error on:") print(missing_ids) return disp_names
# set a date variable so that we can generate a random name for a subject set date = datetime.today() ################ # Connect to zooniverse account, insert your username and password # Panoptes.connect(username='******', password='******') # Or put the user details in a separate file for anonymity f = open("user_details.txt", "r") user_dat = [d.strip() for d in f.readlines()] Panoptes.connect(username=user_dat[0], password=user_dat[1]) # add the project id to access all project/subject details project_id = "10997" # retrieve the user/project details user = User.find(project_id) project = Project.find(project_id) # # look at any project workflows # for workflow in project.links.workflows: # print(workflow.display_name,workflow.id) # retrieve the subject set id print(project.links.subject_sets) # subject_set_id=project.links.subject_sets[-1].id # this is the first subject set (if there are multiple?) subject_set_id = None # generate a new subject set print("subject set id = {}".format(subject_set_id)) # Add some new subjects to the list subject_data_csv = "tutorial_project_subjects.csv" df_subjects = pd.read_csv(subject_data_csv)