small script changes
This commit is contained in:
@ -4,7 +4,7 @@ import Apikeys
|
||||
import pprint
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
apiKey = Apikeys.LUMINATE_US
|
||||
apiKey = Apikeys.SPS
|
||||
course_dict = {}
|
||||
|
||||
COURSES= [
|
||||
@ -22,7 +22,7 @@ def get_course():
|
||||
|
||||
while True:
|
||||
count += 1
|
||||
url = f"https://api2.northpass.com/v2/courses?page={count}"
|
||||
url = f"https://api.northpass.com/v2/courses?page={count}"
|
||||
headers = {"accept": "application/json", "X-Api-Key": apiKey}
|
||||
response = requests.get(url, headers=headers)
|
||||
data = response.json()
|
||||
@ -54,6 +54,7 @@ def get_course():
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
|
||||
write_to_csv(courses)
|
||||
# pp.pprint(courses)
|
||||
# print(len(courses))
|
||||
|
||||
@ -64,7 +65,7 @@ def get_cat_name(cat_id, course_dict, courses):
|
||||
pass
|
||||
elif len(cat_id) == 1:
|
||||
categoryid = cat_id[0]["id"]
|
||||
url = f"https://api2.northpass.com/v2/categories/{categoryid}"
|
||||
url = f"https://api.northpass.com/v2/categories/{categoryid}"
|
||||
cat_resp = requests.get(url, headers=headers)
|
||||
cat_data = cat_resp.json()
|
||||
cat_name = cat_data["data"]["attributes"]["name"]
|
||||
@ -74,7 +75,7 @@ def get_cat_name(cat_id, course_dict, courses):
|
||||
else:
|
||||
for item in cat_id:
|
||||
categoryid = item["id"]
|
||||
url = f"https://api2.northpass.com/v2/categories/{categoryid}"
|
||||
url = f"https://api.northpass.com/v2/categories/{categoryid}"
|
||||
cat_resp = requests.get(url, headers=headers)
|
||||
cat_data = cat_resp.json()
|
||||
cat_name = cat_data["data"]["attributes"]["name"]
|
||||
@ -91,7 +92,7 @@ def get_cat_name(cat_id, course_dict, courses):
|
||||
|
||||
def write_to_csv(courses):
|
||||
df = pd.DataFrame.from_dict(courses)
|
||||
df.to_csv("/Users/normrasmussen/Downloads/walmart_course.csv")
|
||||
df.to_csv("/Users/normrasmussen/Downloads/sps_courses.csv")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@ -1,39 +1,54 @@
|
||||
import pprint
|
||||
import requests
|
||||
import Apikeys
|
||||
import pandas as pd
|
||||
|
||||
APIKEY = Apikeys.CHUBB
|
||||
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 = []
|
||||
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)
|
||||
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"]
|
||||
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)
|
||||
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
|
||||
|
||||
# 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")
|
||||
# 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__":
|
||||
|
||||
Reference in New Issue
Block a user