Files
Gainsight/Scripts/Migration_tool/mark_learner_as_complete.py

102 lines
3.3 KiB
Python
Raw Normal View History

import Calls
baseurl = Calls.BASEURL
def get_people():
email = "norm@rsmsn.co"
if type(email) is str:
learner_uuid = __get_individual_person__(email)
get_courses(learner_uuid)
elif type(email) is list:
person_uuids = __get_group_person__(email)
else:
print("Couldn't recognize the type of data you're trying to use.")
def get_courses(learner_uuid):
course = "Norm Manager Test"
if type(course) is str:
course_uuids = __get_individual_course__(course, learner_uuid)
elif type(course) is list:
courses_uuids = __get_group_course__(course, learner_uuid)
else:
print("Couldn't recognize the type of data you're trying to use.")
def __get_individual_course__(name, learner_uuid):
url = f"{baseurl}/courses?filter[name][eq]={name}"
returned = Calls.get(url)
for items in returned["data"]:
single_uuid = items["id"]
print(f"Cool. Course {single_uuid} exists. Checking enrollments.")
enrollment = __get_enrollment_status__(single_uuid, learner_uuid)
def __get_enrollment_status__(uuid, learner_uuid):
enrollment_url = f"{baseurl}/courses/{uuid}/enrollments?filter[person_id][eq]={learner_uuid}"
enrolled = Calls.get(enrollment_url)
if enrolled['data'] == "":
print("Oof, no enrollments. Not to worry. We'll get one created for you.")
"""
If the learner isn't enrolled yet, we need to create one first. Here's the URL:
(
"/v2/migration/projects/{project_id}/items/{item_id}/enrollment_resources",
"post",
)
"""
else:
print("Nice! We have an enrollment. So now we just need to update progress.")
"""
If the learner is enrolled, we can go straight to creating an attempt.
(
"/v2/migration/projects/{project_id}/items/{item_id}/course_attempt_resources",
"post",
)"""
def __get_group_course__(list):
multiple_uuids = []
for person in email:
url = f"{baseurl}/people?filter[email][eq]={email}"
returned = Calls.get(url)
for items in returned["data"]:
multiple_uuids.append(learner_uuid)
def __get_individual_person__(email):
url = f"{baseurl}/people?filter[email][eq]={email}"
returned = Calls.get(url)
for items in returned["data"]:
if items["attributes"]["registration_status"] == "activated":
single_uuid = items["id"]
print(
f"Awesome. This dude is activated. Proceeding with learner {single_uuid}"
)
return single_uuid
else:
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
def __get_group_person__(list):
multiple_uuids = []
for person in email:
url = f"{baseurl}/people?filter[email][eq]={email}"
returned = Calls.get(url)
for items in returned["data"]:
if items["attributes"]["registration_status"] == "activated":
print("Awesome. This dude is activated. Proceeding.")
single_uuid = items["id"]
multiple_uuids.append(learner_uuid)
else:
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
return multiple_uuids
if __name__ == "__main__":
get_people()
# get_courses()