A migration workedcd ../.. Marking a learner as complete is done. Woohoo.
This commit is contained in:
@ -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)
|
||||
|
||||
@ -120,12 +120,10 @@ def create_project():
|
||||
"""
|
||||
project_name = ""
|
||||
payload = {
|
||||
"data":[
|
||||
"data": [
|
||||
{
|
||||
"type": "migration_projects",
|
||||
"attributes": {
|
||||
"name": project_name
|
||||
},
|
||||
"type": "migration_projects",
|
||||
"attributes": {"name": project_name},
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -137,16 +135,23 @@ def get_all_projects():
|
||||
"""
|
||||
Returns all projects.
|
||||
"""
|
||||
count = 0
|
||||
project_ids = []
|
||||
url = f"{BASEURL}/projects"
|
||||
ret = calls.get(url)
|
||||
while True:
|
||||
count += 1
|
||||
url = f"{BASEURL}/projects?page={count}"
|
||||
ret = calls.get(url)
|
||||
nextlink = ret["links"]
|
||||
|
||||
if ret["data"] != []:
|
||||
for items in ret["data"]:
|
||||
project_ids.append(items["id"])
|
||||
print(f"{ items['attributes']['name'] } -- { items['id'] }")
|
||||
else:
|
||||
print("Looks like there are no projects created!")
|
||||
if ret["data"] != []:
|
||||
for items in ret["data"]:
|
||||
project_ids.append(items["id"])
|
||||
print(f"{ items['attributes']['name'] } -- { items['id'] }")
|
||||
|
||||
if "next" not in nextlink:
|
||||
break
|
||||
else:
|
||||
print("Looks like there are no projects created!")
|
||||
|
||||
return project_ids
|
||||
|
||||
@ -173,6 +178,7 @@ def get_specific_project():
|
||||
ret = calls.get(url)
|
||||
print(ret)
|
||||
|
||||
|
||||
def create_course():
|
||||
project_id = "6c7a21c2-de35-4b9d-9b80-a235401783af"
|
||||
item_id = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e"
|
||||
@ -212,17 +218,17 @@ def create_enrollment():
|
||||
enroll_payload = {
|
||||
"data": [
|
||||
{
|
||||
"attributes": {
|
||||
"uuid": "1234567890",
|
||||
"display_name": "Enrollment Resource Test",
|
||||
"type": "course",
|
||||
"data": {
|
||||
"enrolled_at": formatted_now,
|
||||
"course_id": course_uuid,
|
||||
"person_id": learner_uuid
|
||||
"attributes": {
|
||||
"uuid": "1234567890",
|
||||
"display_name": "Enrollment Resource Test",
|
||||
"type": "course",
|
||||
"data": {
|
||||
"enrolled_at": formatted_now,
|
||||
"course_id": course_uuid,
|
||||
"person_id": learner_uuid,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
enroll_url = calls.post(
|
||||
@ -258,7 +264,7 @@ def create_attempt():
|
||||
"completed_at": formatted_now,
|
||||
"completed_activities": [
|
||||
{"uuid": "1111", "completed_at": formatted_now}
|
||||
]
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -278,6 +284,7 @@ def create_attempt():
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
def get_item():
|
||||
project_id = "c8341414-58da-4291-8507-216da3fbf045"
|
||||
item_id = "4ce43bf5-0c73-427b-ad96-17b5aa8f16b2"
|
||||
@ -287,14 +294,11 @@ def get_item():
|
||||
print(get_item)
|
||||
|
||||
|
||||
|
||||
def check_resources():
|
||||
PROJ_ID = "6c7a21c2-de35-4b9d-9b80-a235401783af"
|
||||
ITEM_ID = "80b95e38-78d1-44b9-8d9f-be96d9c7bf6e"
|
||||
print("Checking resources")
|
||||
get_resources_url = (
|
||||
f"{BASEURL}/projects/{PROJ_ID}/items/{ITEM_ID}/resources"
|
||||
)
|
||||
get_resources_url = f"{BASEURL}/projects/{PROJ_ID}/items/{ITEM_ID}/resources"
|
||||
get_resources = calls.get(get_resources_url)
|
||||
print(get_resources)
|
||||
# if get_resources["data"] == []:
|
||||
@ -305,12 +309,12 @@ def check_resources():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# delete_all_projects()
|
||||
delete_all_projects()
|
||||
# read_json_docs()
|
||||
# create_project()
|
||||
# get_all_projects()
|
||||
get_specific_project()
|
||||
# get_specific_project()
|
||||
# create_enrollment()
|
||||
# check_resources()
|
||||
get_item()
|
||||
# get_item()
|
||||
# create_attempt()
|
||||
|
||||
Reference in New Issue
Block a user