56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
import pprint
|
|
import requests
|
|
import Apikeys
|
|
import pandas as pd
|
|
|
|
APIKEY = Apikeys.SPS
|
|
URL = "https://api.northpass.com/v1/media"
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
|
|
def getMedia(APIKEY, URL):
|
|
count = 0
|
|
list_data = []
|
|
scorm_ids = []
|
|
while True:
|
|
count+=1
|
|
headers = {"accept": "application/json", "X-Api-Key": APIKEY}
|
|
URL = f"{URL}?limit=100&page={count}"
|
|
response = requests.get(URL, headers=headers)
|
|
datas = response.json()
|
|
nextlink = datas["links"]
|
|
# 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"]
|
|
file_size = data["attributes"]["file_size"]
|
|
id_val = data["id"]
|
|
data_dict = { "media_uuid": id_val,
|
|
"file_name": file_name,
|
|
"file_type": file_type,
|
|
"created_at": created_date,
|
|
"file_size": file_size
|
|
}
|
|
# id_val, created_date, file_name)
|
|
list_data.append(data_dict)
|
|
# if "2024-03-12" in created_date:
|
|
# if "scorm" in file_type:
|
|
if "next" not in nextlink:
|
|
break
|
|
|
|
# pp.pprint(list_data)
|
|
# print(len(list_data))
|
|
toCsv(list_data)
|
|
|
|
def toCsv(json):
|
|
js = pd.DataFrame.from_records(json)
|
|
# js = pd.json_normalize(json, "data", ["data"])
|
|
# csv = pd.Series(js)
|
|
js.to_csv("/Users/normrasmussen/Downloads/sps-media-lib.csv")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
getMedia(APIKEY, URL)
|