Nothing left to do today, getting 500 errors for the enrollment and attempt resource endpoints. Everything is set up correctly for hitting those endpoints, but not sure if the 500 is on me or on the application/engineers.
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import Calls
|
||||
import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
baseurl = Calls.BASEURL
|
||||
|
||||
@ -15,44 +15,55 @@ Order of operations:
|
||||
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
|
||||
|
||||
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
|
||||
PPL_UUID = ""
|
||||
PPL_URL = "people"
|
||||
PPL_EMAIL = ""
|
||||
COURSE_URL = "courses"
|
||||
COURSE_UUID = ""
|
||||
COURSE_NAME = ""
|
||||
ITEM_URL = "items"
|
||||
ITEM_ID = ""
|
||||
PROJ_URL = "projects"
|
||||
PROJ_ID = ""
|
||||
|
||||
|
||||
def get_people():
|
||||
email = "norm@rsmsn.co"
|
||||
if type(email) is str:
|
||||
learner = get_individual_person(email)
|
||||
global per
|
||||
per = People(learner[0], learner[1])
|
||||
get_courses(per.ppl_uuid)
|
||||
PPL_UUID = learner[0]
|
||||
PPL_EMAIL = learner[1]
|
||||
get_courses(PPL_UUID)
|
||||
elif type(email) is list:
|
||||
person_uuids = get_group_person(email)
|
||||
else:
|
||||
@ -74,11 +85,10 @@ 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)
|
||||
COURSE_UUID = items["id"]
|
||||
COURSE_NAME = items["attributes"]["name"]
|
||||
print(f"Cool. Course {COURSE_UUID} exists. Checking enrollments.")
|
||||
enrollment = get_enrollment_status(COURSE_UUID, learner_uuid)
|
||||
|
||||
|
||||
def get_enrollment_status(uuid, learner_uuid):
|
||||
@ -86,46 +96,53 @@ def get_enrollment_status(uuid, learner_uuid):
|
||||
f"{baseurl}/courses/{uuid}/enrollments?filter[person_id][eq]={learner_uuid}"
|
||||
)
|
||||
enrolled = Calls.get(enrollment_url)
|
||||
if enrolled["data"] == "":
|
||||
print(enrolled["data"])
|
||||
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": {
|
||||
"attributes": {
|
||||
"enrolled_at": {formatted_now},
|
||||
"course_id": {c.course_uuid},
|
||||
"person_id": {per.ppl_uuid},
|
||||
{"enrolled_at": formatted_now},
|
||||
{"course_id": COURSE_UUID},
|
||||
{"person_id": PPL_UUID},
|
||||
}
|
||||
}
|
||||
}
|
||||
mig_enroll_url = Call.post(
|
||||
f"{baseurl}migration/projects/{p.proj_id}/items/{i.item_id}/enrollment_resources"
|
||||
mig_enroll_url = Calls.post(
|
||||
f"{baseurl}migration/projects/{PROJ_ID}/items/{ITEM_ID}/enrollment_resources",
|
||||
mig_enroll_payload,
|
||||
)
|
||||
print("Cool, enrollment resource has been created. Let's check that it exists.")
|
||||
check_resources()
|
||||
else:
|
||||
print("Nice! We have an enrollment. So now we just need to update progress.")
|
||||
create_attempt(enrolled["data"])
|
||||
# create_attempt(enrolled["data"])
|
||||
|
||||
|
||||
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"
|
||||
print(f"Is there a project ID? {PROJ_ID}")
|
||||
attempt_url = f"{baseurl}/migration/projects/{PROJ_ID}/items/{ITEM_ID}/course_attempt_resources"
|
||||
now = datetime.now()
|
||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
new_attempt_payload = {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"uuid": {"which uuid?"},
|
||||
"display_name": {f"{per.ppl_email}'s Attempt for course {c.course_name}"},
|
||||
"learner_id": {per.ppl_uuid},
|
||||
"course_id": {c.course_uuid},
|
||||
"display_name": {f"{PPL_EMAIL}'s Attempt for course {COURSE_NAME}"},
|
||||
"learner_id": {PPL_UUID},
|
||||
"course_id": {COURSE_UUID},
|
||||
"progress": {"100"},
|
||||
"started_at": {datetime.now() - timedelta(hours = 2)},
|
||||
"started_at": {datetime.now() - timedelta(hours=2)},
|
||||
"completed_at": {formatted_now},
|
||||
"completed_activities": [{"uuid": {"1111"}, "completed_at": {formatted_now}}],
|
||||
"completed_activities": [
|
||||
{"uuid": {"1111"}, "completed_at": {formatted_now}}
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
check_resources()
|
||||
|
||||
|
||||
"""
|
||||
@ -136,15 +153,18 @@ def create_attempt(data):
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
def check_resources():
|
||||
print("Checking resources")
|
||||
get_resources_url = (
|
||||
f"{baseurl}/migration/projects/{p.proj_id}/items/{i.item_id}/resources"
|
||||
f"{baseurl}/migration/projects/{PROJ_ID}/items/{ITEM_ID}/resources"
|
||||
)
|
||||
get_resources = Calls.get(get_resources_url)
|
||||
if get_resources["data"] == []:
|
||||
print("Something went wrong. No resources were created.")
|
||||
else:
|
||||
print("We're in! An enrollment exists, let's create an attempt.")
|
||||
print("We're in! Here's the data:")
|
||||
print(get_resources)
|
||||
|
||||
|
||||
def create_project_item():
|
||||
@ -156,24 +176,22 @@ def create_project_item():
|
||||
"attributes": {"name": project_name},
|
||||
}
|
||||
}
|
||||
proj_url = f"{baseurl}/migration/{Project.proj_url}"
|
||||
print(proj_url)
|
||||
tmp_p = Calls.post(proj_url, proj_payload)
|
||||
global p
|
||||
p = Project(tmp_p["data"]["id"])
|
||||
print(f"Created Project Id: { p.proj_id }")
|
||||
proj_full_url = f"{baseurl}/migration/{PROJ_URL}"
|
||||
print(proj_full_url)
|
||||
tmp_p = Calls.post(proj_full_url, proj_payload)
|
||||
PROJ_ID = tmp_p["data"]["id"]
|
||||
print(f"Created Project Id: {PROJ_ID}")
|
||||
|
||||
item_url = f"{baseurl}/migration/{p.proj_url}/{p.proj_id}/{Item.item_url}"
|
||||
item_full_url = f"{baseurl}/migration/{PROJ_URL}/{PROJ_ID}/{ITEM_URL}"
|
||||
item_payload = {
|
||||
"data": {
|
||||
"type": "migration_items",
|
||||
"attributes": {"type": "courses"},
|
||||
}
|
||||
}
|
||||
item_return = Calls.post(item_url, item_payload)
|
||||
global i
|
||||
i = Item(item_return['data']['id'])
|
||||
print(f"Created Item ID: { i.item_id }")
|
||||
item_return = Calls.post(item_full_url, item_payload)
|
||||
ITEM_ID = item_return["data"]["id"]
|
||||
print(f"Created Item ID: { ITEM_ID }")
|
||||
|
||||
|
||||
def get_group_course(list):
|
||||
|
||||
Reference in New Issue
Block a user