import requests
import pandas as pd
import Apikeys

APIKEY = Apikeys.TALKSPACE_1099
HEADERS = {"accept": "application/json", "X-Api-Key": APIKEY}
DF = pd.DataFrame()


def find_no_ids():
    """
    This function paginates to find all
    """
    count = 0
    user_list = []

    while True:
        count += 1
        url = f"https://api.northpass.com/v2/properties/people?limit=100&page={count}"
        response = requests.get(url, headers=HEADERS)
        response = response.json()
        nextlink = response["links"]
        data = response["data"][0]["attributes"]["properties"]

        if data["user_id"] is None:
            user_tupe = (data["first_name"], data["last_name"], data["email"])
            user_list.append(user_tupe)

        if "next" not in nextlink:
            break
    pp = DF.from_dict(user_list)
    pp.to_csv("~/Downloads/Talkspace_NoIDs_11.3.23.csv")


if __name__ == "__main__":
    find_no_ids()
