A migration workedcd ../.. Marking a learner as complete is done. Woohoo.

This commit is contained in:
Norm Rasmussen
2024-09-05 15:04:49 -04:00
parent 3643bcba35
commit c05336900d
102 changed files with 3030 additions and 121 deletions

View File

@ -76,11 +76,6 @@ ITEM_TYPES = [
"learning_path_attempts",
]
PPL_URL = "people"
COURSE_URL = "courses"
ITEM_URL = "items"
PROJ_URL = "projects"
def get_people():
email = "norm@rsmsn.co"
@ -90,18 +85,31 @@ def get_people():
ppl_email = learner[1]
people[ppl_email] = ppl_uuid
get_courses(ppl_uuid)
create_person_resource()
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_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"]
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"
if type(course) is str:
course_return = get_individual_course(course, learner_uuid)
create_course_resource()
elif type(course) is list:
courses_uuids = get_group_course(course, learner_uuid)
else:
@ -117,9 +125,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.")
enrollment = get_enrollment_status(course_uuid, learner_uuid)
# Use this to get a specific value from the courses sub-dict
# 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):
@ -141,9 +149,9 @@ def get_enrollment_status(uuid, learner_uuid):
"data": {
"enrolled_at": formatted_now,
"course_id": f"{ list(courses.values())[0] }",
"person_id": f"{ list(people.values())[0] }"
}
}
"person_id": f"{ list(people.values())[0] }",
},
},
}
]
}
@ -151,7 +159,7 @@ def get_enrollment_status(uuid, learner_uuid):
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'] != []:
if resource_check["data"] != []:
print("We're in! Enrollment confirmed. Let's create an attempt")
create_item("course_attempts")
@ -162,34 +170,38 @@ def get_enrollment_status(uuid, learner_uuid):
def check_item(itype):
if itype not in items:
create_item(itype)
create_attempt_resource()
item_return = create_item(itype)
return item_return
else:
create_attempt_resource()
return ""
def create_attempt_resource():
print(f"Is there a project ID? {list(probject.values())[0]}")
attempt_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/course_attempt_resources"
print(attempt_url)
now = datetime.now()
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
new_attempt_payload = { "data": [
{
"type": "course_attempts",
item = check_item("course_attempts")
print(f"Is there a resource item with the correct type? {item}")
attempt_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item}/course_attempt_resources"
print(attempt_url)
now = datetime.now()
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
attempt_payload = {
"data": [
{
"type": "course_attempt_resources",
"attributes": {
"uuid": "1234567890",
"display_name": f"{list(people.keys())[0]}'s Attempt for course {list(courses.keys())[0]}",
"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",
"data": {
"learner_id": f"{list(people.keys())[0]}",
"learner_id": f"{list(people.values())[0]}",
"course_id": f"{list(courses.values())[0]}",
"progress": "100",
"started_at": f"{datetime.now() - timedelta(hours=2)}",
"progress": 100,
"enrolled_at": f"{datetime.now() - timedelta(hours=3)}",
"started_at": f"{datetime.now() - timedelta(hours=2)}",
"completed_at": formatted_now,
"completed_activities": [
{
"uuid": "1111",
"completed_at": formatted_now
"id": "63485bb7-0ca4-4ee0-b1ad-a8140c754856",
"completed_at": formatted_now
}
]
}
@ -197,17 +209,16 @@ def create_attempt_resource():
}
]
}
mig_attempt_url = f"{baseurl}migration/projects/{list(probject.values())[0]}/items/{list(probject.values())[0]}/enrollment_resources"
mig_attempt_call = calls.post(attempt_url, new_attempt_payload)
checking = check_resources()
print(checking)
print(attempt_payload)
course_attempt_call = calls.post(attempt_url, attempt_payload)
print(course_attempt_call)
checking = check_resources()
print(checking)
def check_resources():
print("Checking resources")
get_resources_url = (
f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/resources"
)
get_resources_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/resources"
get_resources = calls.get(get_resources_url)
if get_resources["data"] == []:
print("Something went wrong. No resources were created.")
@ -223,17 +234,17 @@ def create_project():
"attributes": {"name": project_name},
}
}
proj_full_url = f"{baseurl}/migration/{PROJ_URL}"
proj_full_url = f"{baseurl}/migration/projects"
tmp_p = calls.post(proj_full_url, proj_payload)
probject[project_name] = tmp_p["data"]["id"]
print(f"Created Project: {probject}")
i_type = "enrollments"
create_item(i_type)
def create_item(i_type):
# Item Type Options: 'courses', 'sections', 'activities', 'people', 'enrollments', 'course_attempts', 'quiz_attempts', 'certificates', 'learning_path_attempts'
item_full_url = (f"{baseurl}/migration/{PROJ_URL}/{list(probject.values())[0]}/{ITEM_URL}")
item_full_url = (
f"{baseurl}/migration/projects/{list(probject.values())[0]}/items"
)
item_type = i_type
print(item_type)
item_payload = {
@ -248,47 +259,49 @@ def create_item(i_type):
print(f"Created Item ID: { items[item_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"
}
}
},
]
"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"
}
}
},
]
"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}")
@ -303,24 +316,7 @@ def get_group_course(list):
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"]
single_email = items["attributes"]["email"]
# first_name = items["attributes"]["name"].split()[0]
# last_name = items["attributes"]["name"].split()[1]
# person = (first_name, last_name, single_email, single_uuid)
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.")
return multiple_uuids
def get_group_person(list):
@ -339,8 +335,11 @@ def get_group_person(list):
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
return multiple_uuids
def start_migration():
start_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/start_migration"
start_url = (
f"{baseurl}/migration/projects/{list(probject.values())[0]}/start_migration"
)
empty = ""
mig = calls.post(start_url, empty)
print(mig.text)