Cleaned up mark learner as complete, can successfully take in a single user and course and migrate them in the academy to mark as complete.

This commit is contained in:
Norm Rasmussen
2024-09-05 18:29:26 -04:00
parent c05336900d
commit d4fdd5702b

View File

@ -1,70 +1,25 @@
"""
Order of operations:
1. Get input of people and course
2. Create Project
3. Create Item with Course_attempt type
4. Create Course Attempt Resource with the same type.
5. Start Migration.
"""
from sys import argv
from utils import calls
from datetime import datetime, timedelta
import uuid
baseurl = calls.BASEURL
"""
Order of operations:
1. Get input of people and course (or ppl/courses) - retain UUIDs of both
2. Check current enrollments of people and courses
3. Create Project and Item
4. If enrollments don't exist, create enrollment object
5. If enrollments do exist, create course attempt object
6. Payload should mark at 100%.
7. Check project & resources.
8. Run migration.
"""
#
# class Project:
# proj_url = "projects"
#
# def __init__(self, PROJ_ID: str):
# self.PROJ_ID = PROJ_ID
#
#
# class Item:
# item_url = "items"
#
# def __init__(self, item_id: str):
# self.item_id = item_id
#
#
# class Courses:
# course_url = "courses"
#
# def __init__(self, course_uuid, course_name):
# self.course_uuid = course_uuid
# self.course_name = course_name
#
#
# class People:
# ppl_url = "people"
#
# def __init__(self, ppl_uuid, ppl_email):
# self.ppl_uuid = ppl_uuid
# self.ppl_email = ppl_email
# probject = {
# "My First Project" : "1234567890",
# "items": {
# "enrollments": "11111111",
# "people": "2222222",
# "courses": "33333333"
# },
# "courses": {
# "course 1": "44444"
# },
# "people": {
# "joe schmo": "5555555"
# }
# }
probject = {}
items = {}
courses = {}
people = {}
ITEM_TYPES = [
item_types = [
"courses",
"sections",
"activities",
@ -75,16 +30,19 @@ ITEM_TYPES = [
"certificates",
"learning_path_attempts",
]
email = argv[1]
course = argv[2]
project_name = argv[3]
def get_people():
email = "norm@rsmsn.co"
def get_people(email, course):
if type(email) is str:
learner = get_individual_person(email)
print(learner)
ppl_uuid = learner[0]
ppl_email = learner[1]
people[ppl_email] = ppl_uuid
get_courses(ppl_uuid)
get_courses(ppl_uuid, course)
elif type(email) is list:
person_uuids = get_group_person(email)
else:
@ -92,22 +50,25 @@ def get_people():
def get_individual_person(email):
url = f"{baseurl}/people?filter[email][eq]={email}"
print(url)
returned = calls.get(url)
for items in returned["data"]:
if items["attributes"]["registration_status"] == "activated":
single_uuid = items["id"]
single_email = items["attributes"]["email"]
print(
f"Awesome. This dude is activated. Proceeding with learner {single_uuid}"
)
return (single_uuid, single_email)
else:
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
if returned["data"] == []:
print("Something is amiss, I couldn't find this user. Are you sure they are in this academy?")
else:
for items in returned["data"]:
if items["attributes"]["registration_status"] == "activated":
single_uuid = items["id"]
single_email = items["attributes"]["email"]
print(
f"Awesome. This dude is activated. Proceeding with learner {single_uuid}"
)
return (single_uuid, single_email)
else:
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
def get_courses(learner_uuid):
course = "Norm Manager Test"
def get_courses(learner_uuid, course):
if type(course) is str:
course_return = get_individual_course(course, learner_uuid)
elif type(course) is list:
@ -125,49 +86,9 @@ def get_individual_course(name, learner_uuid):
course_name = items["attributes"]["name"]
courses[course_name] = course_uuid
print(f"Cool. Course {course_uuid} exists. Checking enrollments.")
# There is no need to create an enrollment or even check. So we can move straight to attempt.
# enrollment = get_enrollment_status(course_uuid, learner_uuid)
create_attempt_resource()
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"] == []:
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 = {
"data": [
{
"type": f"{ list(items.keys())[0] }",
"attributes": {
"uuid": f"{ list(items.values())[0] }",
"display_name": "Enrollment to Course 1",
"data": {
"enrolled_at": formatted_now,
"course_id": f"{ list(courses.values())[0] }",
"person_id": f"{ list(people.values())[0] }",
},
},
}
]
}
mig_enroll_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/enrollment_resources"
mig_enroll = calls.post(mig_enroll_url, mig_enroll_payload)
print("Cool, enrollment resource has been created. Let's check that it exists.")
resource_check = check_resources()
if resource_check["data"] != []:
print("We're in! Enrollment confirmed. Let's create an attempt")
create_item("course_attempts")
else:
print("Nice! We have an enrollment. So now we just need to update progress.")
check_item(mig_enroll_url["data"])
def check_item(itype):
if itype not in items:
item_return = create_item(itype)
@ -188,9 +109,8 @@ def create_attempt_resource():
{
"type": "course_attempt_resources",
"attributes": {
"uuid": "63485bb7-0ca4-4ee0-b1ad-a8140c754856",
# "display_name": f"{list(people.keys())[0]}'s Attempt for course {list(courses.keys())[0]}",
"display_name": "Course Attempt",
"uuid": str(uuid.uuid4()),
"display_name": f"{list(people.keys())[0]}'s Attempt for course {list(courses.keys())[0]}",
"data": {
"learner_id": f"{list(people.values())[0]}",
"course_id": f"{list(courses.values())[0]}",
@ -200,7 +120,7 @@ def create_attempt_resource():
"completed_at": formatted_now,
"completed_activities": [
{
"id": "63485bb7-0ca4-4ee0-b1ad-a8140c754856",
"id": str(uuid.uuid4()),
"completed_at": formatted_now
}
]
@ -226,8 +146,7 @@ def check_resources():
return get_resources
def create_project():
project_name = "Testing Project 2"
def create_project(project_name):
proj_payload = {
"data": {
"type": "migration_projects",
@ -260,52 +179,6 @@ def create_item(i_type):
return item_id
def create_person_resource():
item_id = create_item("people")
persource_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item_id}/person_resources"
persource_payload = {
"data": [
{
"type": "people",
"attributes": {
"uuid": f"{list(people.values())[0]}",
"display_name": f"{list(people.keys())[0]}",
"data": {
"first_name": "FIRST",
"last_name": "NAME",
"email": "norm@rsmsn.co",
},
},
},
]
}
pers_return = calls.post(persource_url, persource_payload)
print(f"Person Resource - {pers_return}")
def create_course_resource():
item_id = create_item("courses")
coursource_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item_id}/person_resources"
coursource_payload = {
"data": [
{
"type": "courses",
"attributes": {
"uuid": f"{list(people.values())[0]}",
"display_name": f"{list(people.keys())[0]}",
"data": {
"name": "Norm's Manager Test",
"short_description": "<string> Short Desc",
"full_description": "<string> Full Desc",
"navigation_mode": "Free Form",
},
},
},
]
}
cours_return = calls.post(coursource_url, coursource_payload)
print(f"Course Resource - {cours_return}")
def get_group_course(list):
multiple_uuids = []
@ -347,6 +220,6 @@ def start_migration():
if __name__ == "__main__":
create_project()
get_people()
start_migration()
create_project(project_name)
get_people(email, course)
# start_migration()