small script changes
This commit is contained in:
@ -4,7 +4,7 @@ import Apikeys
|
|||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
apiKey = Apikeys.LUMINATE_US
|
apiKey = Apikeys.SPS
|
||||||
course_dict = {}
|
course_dict = {}
|
||||||
|
|
||||||
COURSES= [
|
COURSES= [
|
||||||
@ -22,7 +22,7 @@ def get_course():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
count += 1
|
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}
|
headers = {"accept": "application/json", "X-Api-Key": apiKey}
|
||||||
response = requests.get(url, headers=headers)
|
response = requests.get(url, headers=headers)
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -54,6 +54,7 @@ def get_course():
|
|||||||
if "next" not in nextlink:
|
if "next" not in nextlink:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
write_to_csv(courses)
|
||||||
# pp.pprint(courses)
|
# pp.pprint(courses)
|
||||||
# print(len(courses))
|
# print(len(courses))
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ def get_cat_name(cat_id, course_dict, courses):
|
|||||||
pass
|
pass
|
||||||
elif len(cat_id) == 1:
|
elif len(cat_id) == 1:
|
||||||
categoryid = cat_id[0]["id"]
|
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_resp = requests.get(url, headers=headers)
|
||||||
cat_data = cat_resp.json()
|
cat_data = cat_resp.json()
|
||||||
cat_name = cat_data["data"]["attributes"]["name"]
|
cat_name = cat_data["data"]["attributes"]["name"]
|
||||||
@ -74,7 +75,7 @@ def get_cat_name(cat_id, course_dict, courses):
|
|||||||
else:
|
else:
|
||||||
for item in cat_id:
|
for item in cat_id:
|
||||||
categoryid = item["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_resp = requests.get(url, headers=headers)
|
||||||
cat_data = cat_resp.json()
|
cat_data = cat_resp.json()
|
||||||
cat_name = cat_data["data"]["attributes"]["name"]
|
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):
|
def write_to_csv(courses):
|
||||||
df = pd.DataFrame.from_dict(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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@ -1,39 +1,54 @@
|
|||||||
import pprint
|
import pprint
|
||||||
import requests
|
import requests
|
||||||
import Apikeys
|
import Apikeys
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
APIKEY = Apikeys.CHUBB
|
APIKEY = Apikeys.SPS
|
||||||
URL = "https://api.northpass.com/v1/media"
|
URL = "https://api.northpass.com/v1/media"
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
|
|
||||||
|
|
||||||
def getMedia(APIKEY, URL):
|
def getMedia(APIKEY, URL):
|
||||||
|
count = 0
|
||||||
list_data = []
|
list_data = []
|
||||||
scorm_ids = []
|
scorm_ids = []
|
||||||
headers = {"accept": "application/json", "X-Api-Key": APIKEY}
|
while True:
|
||||||
URL = f"{URL}?limit=100"
|
count+=1
|
||||||
response = requests.get(URL, headers=headers)
|
headers = {"accept": "application/json", "X-Api-Key": APIKEY}
|
||||||
datas = response.json()
|
URL = f"{URL}?limit=100&page={count}"
|
||||||
# pp.pprint(datas)
|
response = requests.get(URL, headers=headers)
|
||||||
|
datas = response.json()
|
||||||
|
nextlink = datas["links"]
|
||||||
|
# pp.pprint(datas)
|
||||||
|
|
||||||
for data in datas["data"]:
|
for data in datas["data"]:
|
||||||
file_type = data["attributes"]["file_type"]
|
file_type = data["attributes"]["file_type"]
|
||||||
file_name = data["attributes"]["file_name"]
|
file_name = data["attributes"]["file_name"]
|
||||||
created_date = data["attributes"]["created_at"]
|
created_date = data["attributes"]["created_at"]
|
||||||
id_val = data["id"]
|
file_size = data["attributes"]["file_size"]
|
||||||
if "2024-03-12" in created_date:
|
id_val = data["id"]
|
||||||
if "scorm" in file_type:
|
data_dict = { "media_uuid": id_val,
|
||||||
data_tuple = (id_val, created_date, file_name)
|
"file_name": file_name,
|
||||||
scorm_ids.append(id_val)
|
"file_type": file_type,
|
||||||
list_data.append(data_tuple)
|
"created_at": created_date,
|
||||||
# pp.pprint(list_data)
|
"file_size": file_size
|
||||||
# print(len(list_data))
|
}
|
||||||
print(scorm_ids)
|
# 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):
|
# pp.pprint(list_data)
|
||||||
# js = pd.json_normalize(json, "data", ["data"])
|
# print(len(list_data))
|
||||||
# # csv = pd.Series(js)
|
toCsv(list_data)
|
||||||
# js.to_csv("/Users/normrasmussen/Documents/Northpass/Scripts/API_Tests/spsmedia3.csv")
|
|
||||||
|
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__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
BIN
Scripts/Walmart/PDFs/General FAQs_06.25.2024.pdf
Normal file
BIN
Scripts/Walmart/PDFs/General FAQs_06.25.2024.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user