Scripts for Anthology. Datasnipper notes.
This commit is contained in:
@ -5,7 +5,7 @@ import Apikeys
|
||||
import json
|
||||
|
||||
|
||||
APIKEY = Apikeys.SANDATA
|
||||
APIKEY = Apikeys.ANTHOLOGY
|
||||
groups_dict = {}
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
|
||||
@ -36,7 +36,7 @@ def get_groups(APIKEY):
|
||||
print(groups)
|
||||
|
||||
with open(
|
||||
"/Users/normrasmussen/Downloads/Sandata-Groups.csv", "a+", newline="\n"
|
||||
"/Users/normrasmussen/Downloads/Anthology-Groups.csv", "a+", newline="\n"
|
||||
) as csvfile:
|
||||
for group in groups:
|
||||
for key, value in group.items():
|
||||
|
||||
@ -12,6 +12,8 @@ HEADERS = {
|
||||
}
|
||||
BASEURL = "https://api.northpass.com/v2/"
|
||||
GROUPS = [
|
||||
"Academic Economics",
|
||||
"Academy Use/Navigation",
|
||||
"Accreditation",
|
||||
"Anthology 101",
|
||||
"Baseline",
|
||||
@ -27,6 +29,30 @@ GROUPS = [
|
||||
"Student",
|
||||
]
|
||||
|
||||
def all_groups():
|
||||
"""
|
||||
Get all Group IDs
|
||||
"""
|
||||
gids = []
|
||||
group_count = 0
|
||||
while True:
|
||||
group_count += 1
|
||||
url = f"https://api.northpass.com/v2/groups?page={group_count}"
|
||||
gresponse = requests.get(url, headers=HEADERS)
|
||||
gdata = gresponse.json()
|
||||
gnext = gdata["links"]
|
||||
|
||||
for response in gdata["data"]:
|
||||
group_id = response["id"]
|
||||
group_name = response["attributes"]["name"]
|
||||
group_tupe = (group_id, group_name)
|
||||
print(group_tupe)
|
||||
gids.append(group_tupe)
|
||||
|
||||
if "next" not in gnext:
|
||||
break
|
||||
|
||||
get_courses(gids)
|
||||
|
||||
def group_ids():
|
||||
"""
|
||||
@ -48,6 +74,8 @@ def group_ids():
|
||||
|
||||
get_courses(ids)
|
||||
|
||||
#portfolio t1 - dc50ca43-5071-45b3-bf42-e1e64416ffd0
|
||||
#academy use/nav t1 - 3875a210-f86d-4b4a-a86a-980022374936
|
||||
|
||||
def get_courses(ids):
|
||||
df = pd.DataFrame()
|
||||
@ -55,19 +83,20 @@ def get_courses(ids):
|
||||
for tupe in ids:
|
||||
id = tupe[0]
|
||||
group = tupe[1]
|
||||
print(group)
|
||||
print(f"Get Courses Function. Group:{ group } and id: {id}")
|
||||
for count in range(1, 10):
|
||||
url2 = f"groups/{id}/courses?limit=100&page={count}"
|
||||
courseurl = f"{BASEURL}{url2}"
|
||||
coursereq = requests.get(courseurl, headers=HEADERS)
|
||||
coursedata = coursereq.json()
|
||||
print(coursedata)
|
||||
nextlink = coursedata["links"]
|
||||
for cdata in coursedata["included"]:
|
||||
if cdata["attributes"]["status"] == "archived":
|
||||
coursedict = parse_data(cdata, group)
|
||||
print(f"Coursedict --> {coursedict} for page {count}")
|
||||
if coursedict is not None:
|
||||
courses.append(coursedict)
|
||||
# if cdata["attributes"]["status"] == "archived":
|
||||
coursedict = parse_data(cdata, group)
|
||||
print(f"Coursedict --> {coursedict} for page {count}")
|
||||
if coursedict is not None:
|
||||
courses.append(coursedict)
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
|
||||
@ -96,4 +125,5 @@ def parse_data(cdata, group):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
group_ids()
|
||||
# group_ids()
|
||||
all_groups()
|
||||
|
||||
Reference in New Issue
Block a user