Divided util into it's own module. Struggling with class variables and using them across many functions...
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import Calls
|
||||
import datetime
|
||||
|
||||
baseurl = Calls.BASEURL
|
||||
|
||||
@ -18,21 +19,21 @@ Order of operations:
|
||||
class Project:
|
||||
proj_url = "projects"
|
||||
|
||||
def __init__(self, proj_id: str):
|
||||
def __init__(self):
|
||||
self.proj_id = proj_id
|
||||
|
||||
|
||||
class Item:
|
||||
item_url = "items"
|
||||
|
||||
def __init__(self, item_id: str):
|
||||
def __init__(self):
|
||||
self.item_id = item_id
|
||||
|
||||
|
||||
class Courses:
|
||||
course_url = "courses"
|
||||
|
||||
def __init__(self, course_uuid, course_name):
|
||||
def __init__(self):
|
||||
self.course_uuid = course_uuid
|
||||
self.course_name = course_name
|
||||
|
||||
@ -40,16 +41,24 @@ class Courses:
|
||||
class People:
|
||||
ppl_url = "people"
|
||||
|
||||
def __init__(self, ppl_uuid, ppl_email):
|
||||
def __init__(self):
|
||||
self.ppl_uuid = ppl_uuid
|
||||
self.ppl_email = ppl_email
|
||||
|
||||
# per = People()
|
||||
# i = Item()
|
||||
# p = Product()
|
||||
# c = Courses()
|
||||
|
||||
def get_people():
|
||||
def get_people(proj_id, proj_url, item_id, item_url):
|
||||
email = "norm@rsmsn.co"
|
||||
if type(email) is str:
|
||||
learner_uuid = get_individual_person(email)
|
||||
get_courses(learner_uuid)
|
||||
learner = get_individual_person(email)
|
||||
People.ppl_uuid = learner[0]
|
||||
People.ppl_email = learner[1]
|
||||
ppl_uuid = People.ppl_uuid
|
||||
ppl_email = People.ppl_email
|
||||
get_courses(ppl_uuid)
|
||||
elif type(email) is list:
|
||||
person_uuids = get_group_person(email)
|
||||
else:
|
||||
@ -81,23 +90,66 @@ def get_enrollment_status(uuid, learner_uuid):
|
||||
f"{baseurl}/courses/{uuid}/enrollments?filter[person_id][eq]={learner_uuid}"
|
||||
)
|
||||
enrolled = Calls.get(enrollment_url)
|
||||
print(f"Is there a project ID? {Project.proj_id}")
|
||||
if enrolled["data"] == "":
|
||||
now = datetime.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.")
|
||||
"""
|
||||
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",
|
||||
)
|
||||
"""
|
||||
mig_enroll_payload = {
|
||||
"data": {
|
||||
"attributes": {
|
||||
"enrolled_at": {formatted_now},
|
||||
"course_id": {c.course_uuid},
|
||||
"person_id": {per.ppl_uuid},
|
||||
}
|
||||
}
|
||||
}
|
||||
mig_enroll_url = Call.post(
|
||||
f"{baseurl}migration/projects/{p.proj_id}/items/{i.item_id}/enrollment_resources"
|
||||
)
|
||||
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.")
|
||||
"""
|
||||
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",
|
||||
)"""
|
||||
create_attempt()
|
||||
|
||||
|
||||
def create_attempt():
|
||||
print(f"Is there a project ID? {proj_id}")
|
||||
attempt_url = f"{baseurl}/migration/projects/{proj_id}/items/{item_id}/course_attempt_resources"
|
||||
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},
|
||||
"progress": {"100"},
|
||||
"started_at": {datetime.now() - timedelta(hours = 2)},
|
||||
"completed_at": {formatted_now},
|
||||
"completed_activities": [{"uuid": {"1111"}, "completed_at": {formatted_now}}],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
"""
|
||||
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 check_resources():
|
||||
get_resources_url = (
|
||||
f"{baseurl}/migration/projects/{p.proj_id}/items/{i.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.")
|
||||
|
||||
|
||||
def create_project_item():
|
||||
@ -112,18 +164,22 @@ def create_project_item():
|
||||
proj_url = f"{baseurl}/migration/{Project.proj_url}"
|
||||
print(proj_url)
|
||||
tmp_p = Calls.post(proj_url, proj_payload)
|
||||
p = Project(tmp_p['data']['id'])
|
||||
print(p.proj_id)
|
||||
Project.proj_id = tmp_p["data"]["id"]
|
||||
proj_id = Project.proj_id
|
||||
print(f"Created Project Id: { proj_id }")
|
||||
|
||||
item_url = f"{baseurl}/migration/{Project.proj_url}/{p.proj_id}/{Item.item_url}"
|
||||
print(item_url)
|
||||
item_url = f"{baseurl}/migration/{Project.proj_url}/{proj_id}/{Item.item_url}"
|
||||
item_payload = {
|
||||
"data": {
|
||||
"type": "migration_items",
|
||||
"attributes": {"type": "courses"},
|
||||
}
|
||||
}
|
||||
i = Item(Calls.post(item_url, item_payload))
|
||||
item_return = Calls.post(item_url, item_payload)
|
||||
Item.item_id = item_return['data']['id']
|
||||
item_id = Item.item_id
|
||||
print(f"Created Item ID: { item_id }")
|
||||
get_people(proj_id, proj_url, item_id, item_url)
|
||||
|
||||
|
||||
def get_group_course(list):
|
||||
@ -143,10 +199,11 @@ def get_individual_person(email):
|
||||
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
|
||||
return (single_uuid, single_email)
|
||||
else:
|
||||
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
|
||||
|
||||
@ -161,7 +218,8 @@ def get_group_person(list):
|
||||
if items["attributes"]["registration_status"] == "activated":
|
||||
print("Awesome. This dude is activated. Proceeding.")
|
||||
single_uuid = items["id"]
|
||||
multiple_uuids.append(learner_uuid)
|
||||
single_email = items["attributes"]["email"]
|
||||
multiple_uuids.append((single_uuid, single_email))
|
||||
else:
|
||||
print("Sorry bruv, but ya mate ain't activated yet. Can't do nuffin.")
|
||||
return multiple_uuids
|
||||
@ -170,4 +228,3 @@ def get_group_person(list):
|
||||
if __name__ == "__main__":
|
||||
create_project_item()
|
||||
# get_people()
|
||||
# get_courses()
|
||||
|
||||
@ -17,7 +17,7 @@ Notes:
|
||||
"""
|
||||
|
||||
import json
|
||||
import Calls
|
||||
from utils import calls, apikeys
|
||||
|
||||
JSONDOC = "./api_docs.json"
|
||||
BASEURL = "https://api.northpass.com/v2/migration"
|
||||
@ -125,11 +125,14 @@ def get_all_projects():
|
||||
"""
|
||||
project_ids = []
|
||||
url = f"{BASEURL}/projects"
|
||||
ret = Calls.get(url)
|
||||
ret = calls.get(url)
|
||||
|
||||
for items in ret["data"]:
|
||||
project_ids.append(items['id'])
|
||||
print(f"{ items['attributes']['name'] } -- { items['id'] }")
|
||||
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!")
|
||||
|
||||
return project_ids
|
||||
|
||||
@ -140,7 +143,7 @@ def delete_all_projects():
|
||||
project_ids = get_all_projects()
|
||||
for proj in project_ids:
|
||||
url = f"{BASEURL}/projects/{proj}"
|
||||
Calls.delete(url)
|
||||
calls.delete(url)
|
||||
|
||||
def get_specific_project():
|
||||
"""
|
||||
@ -148,7 +151,7 @@ def get_specific_project():
|
||||
"""
|
||||
proj_id = "13aa7aed-3fb5-4488-9185-3befd0c1ae86"
|
||||
url = f"{BASEURL}/projects/{proj_id}"
|
||||
Calls.get(url)
|
||||
calls.get(url)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
0
Scripts/Migration_tool/utils/__init__.py
Normal file
0
Scripts/Migration_tool/utils/__init__.py
Normal file
BIN
Scripts/Migration_tool/utils/__pycache__/apikeys.cpython-310.pyc
Normal file
BIN
Scripts/Migration_tool/utils/__pycache__/apikeys.cpython-310.pyc
Normal file
Binary file not shown.
BIN
Scripts/Migration_tool/utils/__pycache__/calls.cpython-310.pyc
Normal file
BIN
Scripts/Migration_tool/utils/__pycache__/calls.cpython-310.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user