2023-10-05 17:26:26 -04:00
|
|
|
"""
|
|
|
|
|
Small script to grab the list of courses from Northpass API
|
|
|
|
|
along with their status & description and write them to a CSV.
|
|
|
|
|
"""
|
|
|
|
|
import requests
|
|
|
|
|
import pandas as pd
|
|
|
|
|
import Apikeys
|
|
|
|
|
|
2023-10-17 17:28:07 -04:00
|
|
|
APIKEY = Apikeys.talkspace_1099
|
|
|
|
|
COURSES = ["Getting Started at Talkspace (ICP - 2023)",
|
|
|
|
|
"Getting Started at Talkspace (Prescriber)",
|
|
|
|
|
"Getting Started at Talkspace (Associate ICP)",
|
|
|
|
|
"Talkspace Managed Care Plans"]
|
2023-10-05 17:26:26 -04:00
|
|
|
|
|
|
|
|
def get_course():
|
|
|
|
|
"""
|
|
|
|
|
This function paginates through API responses to get the courses information
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
count = 0
|
|
|
|
|
courses = []
|
|
|
|
|
course_dict = {}
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
count += 1
|
2023-10-17 17:28:07 -04:00
|
|
|
url = f"https://api.northpass.com/v2/courses?page={count}"
|
2023-10-05 17:26:26 -04:00
|
|
|
headers = {"accept": "application/json", "X-Api-Key": APIKEY}
|
|
|
|
|
response = requests.get(url, headers=headers)
|
|
|
|
|
data = response.json()
|
|
|
|
|
nextlink = data["links"]
|
|
|
|
|
|
|
|
|
|
for response in data["data"]:
|
|
|
|
|
status = response["attributes"]["status"]
|
|
|
|
|
if status == "live":
|
|
|
|
|
uuid = response["id"]
|
|
|
|
|
name = response["attributes"]["name"]
|
2023-10-17 17:28:07 -04:00
|
|
|
if name in COURSES:
|
|
|
|
|
# full_description = response["attributes"]["full_description"]
|
|
|
|
|
course_dict = {
|
|
|
|
|
"id": uuid,
|
|
|
|
|
"name": name,
|
|
|
|
|
# "status": status,
|
|
|
|
|
# "full_description": full_description,
|
|
|
|
|
}
|
2023-10-05 17:26:26 -04:00
|
|
|
|
2023-10-17 17:28:07 -04:00
|
|
|
try:
|
|
|
|
|
courses.append(course_dict)
|
|
|
|
|
except TypeError as e:
|
|
|
|
|
print(f"Error: {e}")
|
|
|
|
|
finally:
|
|
|
|
|
# write_to_csv(courses)
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
pass
|
|
|
|
|
print(courses)
|
2023-10-05 17:26:26 -04:00
|
|
|
|
|
|
|
|
if "next" not in nextlink:
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def write_to_csv(courses):
|
|
|
|
|
"""
|
|
|
|
|
Function to write the list of dictionaries to a CSV using pandas.
|
|
|
|
|
Takes on parameter, the list of courses.
|
|
|
|
|
"""
|
|
|
|
|
df = pd.DataFrame.from_dict(courses)
|
2023-10-06 16:39:05 -04:00
|
|
|
df.to_csv("/Users/normrasmussen/Downloads/courses_descriptions.csv")
|
2023-10-05 17:26:26 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
get_course()
|