def main(): names = set() dupes = [] LIMIT = 1000 OFFSET = 0 more = True while more: base_url = 'https://api.humanitarian.id/api/v2/user?limit='+str(LIMIT)+'&offset='\ +str(OFFSET)+'&sort=name&access_token=' full_url = base_url + base.API_KEY content = base.open_url(full_url) if len(content) != 0: for person in content: first = person['given_name'] last = person['family_name'] full = first.title() + ' ' + last.title() if full not in names: names.add(full) else: if full not in dupes: dupes.append(full) OFFSET += 1000 else: break # Update Google Sheet try: worksheet = base.wks.add_worksheet(title="Duplicates", rows=(len(dupes) + 4), cols=10) worksheet.update_acell( 'A2', "Duplicate accounts (Based on given and family name matching)") worksheet.update_acell('A3', "Name") except APIError: worksheet = base.wks.worksheet("Duplicates") names_list = worksheet.range('A4:A' + str(len(dupes) + 3)) index = 0 for cell in names_list: cell.value = dupes[index] index += 1 worksheet.update_cells(names_list) # Update last modified updated = base.update_timestamp(worksheet) worksheet.update_acell('A1', updated)
def main(): LIMIT = 100 OFFSET = 0 more = True ids = [] firsts = [] lasts = [] while more: base_url = 'https://api.humanitarian.id/api/v2/user?verified=true&organization.orgTypeId=443&limit='\ +str(LIMIT)+'&offset='+str(OFFSET)+'&access_token=' full_url = base_url + base.API_KEY content = base.open_url(full_url) if len(content) != 0: for user in content: ids.append(user['_id']) firsts.append(user['given_name']) lasts.append(user['family_name']) OFFSET += 100 else: more = False # Update Google Sheet try: worksheet = base.wks.add_worksheet(title="Verified - Other", rows=(len(ids) + 4), cols=10) worksheet.update_acell( 'A2', "Verified users with OTHER as organization type") worksheet.update_acell('A3', "User ID") worksheet.update_acell('B3', "Given Name") worksheet.update_acell('C3', "Family Name") except APIError: worksheet = base.wks.worksheet("Verified - Other") # Select range id_list = worksheet.range('A4:A' + str(len(ids) + 3)) first_list = worksheet.range('B4:B' + str(len(firsts) + 3)) last_list = worksheet.range('C4:C' + str(len(lasts) + 3)) index = 0 for cell in id_list: cell.value = ids[index] index += 1 index = 0 for cell in first_list: cell.value = firsts[index] index += 1 index = 0 for cell in last_list: cell.value = lasts[index] index += 1 # Update in batch - avoids API timeout problem worksheet.update_cells(id_list) worksheet.update_cells(first_list) worksheet.update_cells(last_list) # Update last modified updated = base.update_timestamp(worksheet) worksheet.update_acell('A1', updated)
def main(): LIMIT = 1000 OFFSET = 0 ids = [] firsts = [] lasts = [] more = True while more: base_url = 'https://api.humanitarian.id/api/v2/user?verified=false&authOnly=false&limit='\ +str(LIMIT)+'&offset='+str(OFFSET)+'&access_token=' full_url = base_url + base.API_KEY content = base.open_url(full_url) if len(content) != 0: for user in content: try: org = user['organization'] if (org == None) or (len(org) == 0): ids.append(user['_id']) firsts.append(user['given_name']) lasts.append(user['family_name']) else: continue except KeyError: ids.append(user['_id']) firsts.append(user['given_name']) lasts.append(user['family_name']) OFFSET += 1000 else: more = False # Update Google Sheet try: worksheet = base.wks.add_worksheet(title="Unverified - No Org", rows=(len(ids) + 4), cols=10) worksheet.update_acell( 'A2', "Unverified users without organization (excludes auth users)") worksheet.update_acell('A3', "User ID") worksheet.update_acell('B3', "Given Name") worksheet.update_acell('C3', "Family Name") except APIError: worksheet = base.wks.worksheet("Unverified - No Org") # Select range id_list = worksheet.range('A4:A' + str(len(ids) + 3)) first_list = worksheet.range('B4:B' + str(len(firsts) + 3)) last_list = worksheet.range('C4:C' + str(len(lasts) + 3)) index = 0 for cell in id_list: cell.value = ids[index] index += 1 index = 0 for cell in first_list: cell.value = firsts[index] index += 1 index = 0 for cell in last_list: cell.value = lasts[index] index += 1 # Update in batch - avoids API timeout problem worksheet.update_cells(id_list) worksheet.update_cells(first_list) worksheet.update_cells(last_list) # Update last modified updated = base.update_timestamp(worksheet) worksheet.update_acell('A1', updated)
def main(): LIMIT = 1000 OFFSET = 0 ids = [] firsts = [] lasts = [] more = True while more: base_url = 'https://api.humanitarian.id/api/v2/user?verified=true&authOnly=false&limit='+\ str(LIMIT)+'&offset='+str(OFFSET)+'&access_token=' full_url = base_url + base.API_KEY content = base.open_url(full_url) print('Getting', LIMIT, 'new records...') if len(content) != 0: for user in content: try: location = user['locations'] if (location == None) or (len(location) == 0): ids.append(user['_id']) firsts.append(user['given_name']) lasts.append(user['family_name']) else: continue except KeyError: ids.append(user['_id']) firsts.append(user['given_name']) lasts.append(user['family_name']) OFFSET += 1000 else: more = False # Update Google Sheet try: worksheet = base.wks.worksheet("Verified - No Location") except APIError as e: print("{}: {}".format(type(e).__name__, e)) try: worksheet = base.wks.add_worksheet(title="Verified - No Location", rows=(len(ids) + 4), cols=10) worksheet.update_acell( 'A2', "Verified profiles without location (excludes auth users)") worksheet.update_acell('A3', "User ID") worksheet.update_acell('B3', "Given Name") worksheet.update_acell('C3', "Family Name") except: print("Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]) except: print("Unexpected error:", sys.exc_info()[0], sys.exc_info()[1]) # Select range id_list = worksheet.range('A4:A' + str(len(ids) + 3)) first_list = worksheet.range('B4:B' + str(len(firsts) + 3)) last_list = worksheet.range('C4:C' + str(len(lasts) + 3)) index = 0 for cell in id_list: cell.value = ids[index] index += 1 index = 0 for cell in first_list: cell.value = firsts[index] index += 1 index = 0 for cell in last_list: cell.value = lasts[index] index += 1 # Update in batch - avoids API timeout problem worksheet.update_cells(id_list) worksheet.update_cells(first_list) worksheet.update_cells(last_list) # Update last modified updated = base.update_timestamp(worksheet) worksheet.update_acell('A1', updated)
def main(): LIMIT = 100 OFFSET = 0 more = True ids = [] names = [] counts = [] while more: base_url = 'https://api.humanitarian.id/api/v2/list?limit='+str(LIMIT)+'&offset='+str(OFFSET)+\ '&sort=-count&access_token=' full_url = base_url + base.API_KEY content = base.open_url(full_url) for list in content: count = list['count'] if count < 20: more = False break ids.append(list['_id']) names.append(list['label']) counts.append(count) OFFSET += 100 # Update Google Sheet try: worksheet = base.wks.add_worksheet(title="20+ Contacts", rows=(len(ids) + 4), cols=10) worksheet.update_acell('A2', "Lists with 20+ contacts") worksheet.update_acell('A3', "List ID") worksheet.update_acell('B3', "List Label") worksheet.update_acell('C3', "Num Contacts") except APIError: worksheet = base.wks.worksheet("20+ Contacts") # Select range id_list = worksheet.range('A4:A' + str(len(ids) + 3)) name_list = worksheet.range('B4:B' + str(len(names) + 3)) count_list = worksheet.range('C4:C' + str(len(counts) + 3)) index = 0 for cell in id_list: cell.value = ids[index] index += 1 index = 0 for cell in name_list: cell.value = names[index] index += 1 index = 0 for cell in count_list: cell.value = counts[index] index += 1 # Update in batch - avoids API timeout problem worksheet.update_cells(id_list) worksheet.update_cells(name_list) worksheet.update_cells(count_list) # Update last modified updated = base.update_timestamp(worksheet) worksheet.update_acell('A1', updated)
def main(): LIMIT = 1000 OFFSET = 0 ids = [] firsts = [] lasts = [] more = True while more: base_url = 'https://api.humanitarian.id/api/v2/user?verified=false&sort=name&limit='+str(LIMIT)+\ '&offset='+str(OFFSET)+'&access_token=' full_url = base_url + base.API_KEY content = base.open_url(full_url) if len(content) != 0: for user in content: id = user['_id'] first = user['given_name'] last = user['family_name'] if (len(first) <= 1) or (len(last) <= 1): ids.append(id) firsts.append(first) lasts.append(last) OFFSET += 1000 else: more = False # Update Google Sheet try: worksheet = base.wks.add_worksheet(title="Unverified - Incomplete", rows=(len(ids) + 4), cols=10) worksheet.update_acell( 'A2', "Unverified profiles with potentially incomplete names") worksheet.update_acell('A3', "User ID") worksheet.update_acell('B3', "Given Name") worksheet.update_acell('C3', "Family Name") except APIError: worksheet = base.wks.worksheet("Unverified - Incomplete") # Select range id_list = worksheet.range('A4:A' + str(len(ids) + 3)) first_list = worksheet.range('B4:B' + str(len(firsts) + 3)) last_list = worksheet.range('C4:C' + str(len(lasts) + 3)) index = 0 for cell in id_list: cell.value = ids[index] index += 1 index = 0 for cell in first_list: cell.value = firsts[index] index += 1 index = 0 for cell in last_list: cell.value = lasts[index] index += 1 # Update in batch - avoids API timeout problem worksheet.update_cells(id_list) worksheet.update_cells(first_list) worksheet.update_cells(last_list) # Update last modified updated = base.update_timestamp(worksheet) worksheet.update_acell('A1', updated)