import pprint
import requests
import Apikeys

APIKEY = Apikeys.CHUBB
URL = "https://api.northpass.com/v1/media"
pp = pprint.PrettyPrinter(indent=4)


def getMedia(APIKEY, URL):
    list_data = []
    scorm_ids = []
    headers = {"accept": "application/json", "X-Api-Key": APIKEY}
    URL = f"{URL}?limit=100"
    response = requests.get(URL, headers=headers)
    datas = response.json()
    # pp.pprint(datas)

    for data in datas["data"]:
        file_type = data["attributes"]["file_type"]
        file_name = data["attributes"]["file_name"]
        created_date = data["attributes"]["created_at"]
        id_val = data["id"]
        if "2024-03-12" in created_date:
            if "scorm" in file_type:
                data_tuple = (id_val, created_date, file_name)
                scorm_ids.append(id_val)
                list_data.append(data_tuple)
    # pp.pprint(list_data)
    # print(len(list_data))
    print(scorm_ids)

# def toCsv(json):
#     js = pd.json_normalize(json, "data", ["data"])
#     # csv = pd.Series(js)
#     js.to_csv("/Users/normrasmussen/Documents/Northpass/Scripts/API_Tests/spsmedia3.csv")


if __name__ == "__main__":
    getMedia(APIKEY, URL)
