import pprint import requests import Apikeys BASEURL = "https://api.northpass.com/v2" APIKEY = Apikeys.ANTHOLOGY HEADERS = {"accept": "*/*","X-Api-Key": APIKEY,"content-type": "application/json"} pp=pprint.PrettyPrinter(indent=4) def main(): count = 0 while True: count += 1 getpplprops = f"{BASEURL}/properties/people" # getppl = f"{BASEURL}/people?limit=100&page={count}" getpplreq = requests.get(getpplprops, headers=HEADERS).json() nextlink = getpplreq["links"] for name in getpplreq['data']: uuid = name['id'] subscription_levels = name['attributes']['properties']['subscription_levels'] if subscription_levels is not None:# or "Core" not in subscription_levels: if "Core" not in subscription_levels: try: subs = subscription_levels.split(", ") except AttributeError as e: print(e) subs = subscription_levels # print(uuid, subs) print(name["attributes"]["properties"]["email"]) change_property_values(uuid, subs) print(count) if "next" not in nextlink or count == 2: break def change_property_values(uuid, subs): strip_list = [] subs = list(filter(lambda x: x != '', subs)) subs = list(filter(lambda x: x != ' ', subs)) print("\n") print(subs) print(len(subs)) for item in subs: stripped = item.strip() x = "" if "Enhanced+" in stripped: x = stripped.replace('Enhanced+', 'Premium') strip_list.append(x) else: if "Enhanced" in stripped: x = stripped.replace("Enhanced", "Core") elif "Essential" in stripped: x = stripped.replace("Essential", "Core") strip_list.append(x) strip_list = list(filter(lambda x: x != '', strip_list)) strip_list = set(strip_list) print(strip_list) print(len(strip_list)) if __name__ == "__main__": main() # str1 = "Anthology Encompass: Essential" # str2 = str1.replace("Essential", "Core") # print(str1) # print(str2) """ Anthology 101: Essential Anthology Encompass: Essential Anthology Insight: Essential Blackboard Learn: Essential Anthology Planning: Essential Power BI: Essential Anthology Student: Essential Anthology Student: Enhanced Anthology Student: Enhanced+ Anthology National University: Enhanced+ """