2023-11-14 18:12:34 -05:00
|
|
|
import pprint
|
2022-12-07 14:10:10 -05:00
|
|
|
import requests
|
2023-11-14 18:12:34 -05:00
|
|
|
import Apikeys
|
2022-12-07 14:10:10 -05:00
|
|
|
|
2023-11-14 18:12:34 -05:00
|
|
|
APIKEY = Apikeys.CHUBB
|
|
|
|
|
URL = "https://api.northpass.com/v1/media"
|
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
2022-12-07 14:10:10 -05:00
|
|
|
|
|
|
|
|
|
2023-11-14 18:12:34 -05:00
|
|
|
def getMedia(APIKEY, URL):
|
|
|
|
|
list_data = []
|
|
|
|
|
headers = {"accept": "application/json", "X-Api-Key": APIKEY}
|
|
|
|
|
URL = f"{URL}?limit=100"
|
|
|
|
|
response = requests.get(URL, headers=headers)
|
|
|
|
|
datas = response.json()
|
2022-12-07 14:10:10 -05:00
|
|
|
|
2023-11-14 18:12:34 -05:00
|
|
|
for data in datas["data"]:
|
|
|
|
|
file_type = data["attributes"]["file_type"]
|
|
|
|
|
id_val = data["id"]
|
|
|
|
|
create_link = data["links"]["create_course_from_file"]
|
|
|
|
|
if "scorm" in file_type:
|
|
|
|
|
data_tuple = (id_val, file_type, create_link)
|
|
|
|
|
list_data.append(data_tuple)
|
|
|
|
|
pp.pprint(list_data)
|
|
|
|
|
print(len(list_data))
|
2022-12-07 14:10:10 -05:00
|
|
|
|
2023-11-14 18:12:34 -05:00
|
|
|
# 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")
|
2022-12-07 14:10:10 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-11-14 18:12:34 -05:00
|
|
|
getMedia(APIKEY, URL)
|