From 35194352f58923705578af3ac2830d0f1fa0bacf Mon Sep 17 00:00:00 2001 From: Norm Rasmussen Date: Sun, 1 Sep 2024 08:42:47 -0400 Subject: [PATCH] okay, made class variables global. Working much better now. --- .../mark_course_as_complete.py | 54 +++++++++---------- 1 file changed, 24 insertions(+), 30 deletions(-) diff --git a/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py b/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py index e66e450e..bf567b48 100644 --- a/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py +++ b/Scripts/Migration_tool/Mark_Course_As_Complete/mark_course_as_complete.py @@ -19,21 +19,21 @@ Order of operations: class Project: proj_url = "projects" - def __init__(self): + def __init__(self, proj_id: str): self.proj_id = proj_id class Item: item_url = "items" - def __init__(self): + def __init__(self, item_id: str): self.item_id = item_id class Courses: course_url = "courses" - def __init__(self): + def __init__(self, course_uuid, course_name): self.course_uuid = course_uuid self.course_name = course_name @@ -41,24 +41,18 @@ class Courses: class People: ppl_url = "people" - def __init__(self): + def __init__(self, ppl_uuid, ppl_email): self.ppl_uuid = ppl_uuid self.ppl_email = ppl_email -# per = People() -# i = Item() -# p = Product() -# c = Courses() -def get_people(proj_id, proj_url, item_id, item_url): +def get_people(): email = "norm@rsmsn.co" if type(email) is str: learner = get_individual_person(email) - People.ppl_uuid = learner[0] - People.ppl_email = learner[1] - ppl_uuid = People.ppl_uuid - ppl_email = People.ppl_email - get_courses(ppl_uuid) + global per + per = People(learner[0], learner[1]) + get_courses(per.ppl_uuid) elif type(email) is list: person_uuids = get_group_person(email) else: @@ -68,7 +62,7 @@ def get_people(proj_id, proj_url, item_id, item_url): def get_courses(learner_uuid): course = "Norm Manager Test" if type(course) is str: - course_uuids = get_individual_course(course, learner_uuid) + course_return = get_individual_course(course, learner_uuid) elif type(course) is list: courses_uuids = get_group_course(course, learner_uuid) else: @@ -80,7 +74,9 @@ def get_individual_course(name, learner_uuid): returned = Calls.get(url) for items in returned["data"]: + global c single_uuid = items["id"] + c = Courses(single_uuid, items["attributes"]["name"]) print(f"Cool. Course {single_uuid} exists. Checking enrollments.") enrollment = get_enrollment_status(single_uuid, learner_uuid) @@ -90,9 +86,8 @@ def get_enrollment_status(uuid, learner_uuid): f"{baseurl}/courses/{uuid}/enrollments?filter[person_id][eq]={learner_uuid}" ) enrolled = Calls.get(enrollment_url) - print(f"Is there a project ID? {Project.proj_id}") if enrolled["data"] == "": - now = datetime.datetime.now() + now = datetime.now() formatted_now = now.strftime("%Y-%m-%d %H:%M:%S") print("Oof, no enrollments. Not to worry. We'll get one created for you.") mig_enroll_payload = { @@ -111,12 +106,12 @@ def get_enrollment_status(uuid, learner_uuid): check_resources() else: print("Nice! We have an enrollment. So now we just need to update progress.") - create_attempt() + create_attempt(enrolled["data"]) -def create_attempt(): - print(f"Is there a project ID? {proj_id}") - attempt_url = f"{baseurl}/migration/projects/{proj_id}/items/{item_id}/course_attempt_resources" +def create_attempt(data): + print(f"Is there a project ID? {p.proj_id}") + attempt_url = f"{baseurl}/migration/projects/{p.proj_id}/items/{i.item_id}/course_attempt_resources" new_attempt_payload = { "data": { "attributes": { @@ -164,11 +159,11 @@ def create_project_item(): proj_url = f"{baseurl}/migration/{Project.proj_url}" print(proj_url) tmp_p = Calls.post(proj_url, proj_payload) - Project.proj_id = tmp_p["data"]["id"] - proj_id = Project.proj_id - print(f"Created Project Id: { proj_id }") + global p + p = Project(tmp_p["data"]["id"]) + print(f"Created Project Id: { p.proj_id }") - item_url = f"{baseurl}/migration/{Project.proj_url}/{proj_id}/{Item.item_url}" + item_url = f"{baseurl}/migration/{p.proj_url}/{p.proj_id}/{Item.item_url}" item_payload = { "data": { "type": "migration_items", @@ -176,10 +171,9 @@ def create_project_item(): } } item_return = Calls.post(item_url, item_payload) - Item.item_id = item_return['data']['id'] - item_id = Item.item_id - print(f"Created Item ID: { item_id }") - get_people(proj_id, proj_url, item_id, item_url) + global i + i = Item(item_return['data']['id']) + print(f"Created Item ID: { i.item_id }") def get_group_course(list): @@ -227,4 +221,4 @@ def get_group_person(list): if __name__ == "__main__": create_project_item() - # get_people() + get_people()