163 lines
5.2 KiB
Python
163 lines
5.2 KiB
Python
"""
|
|
This file serves as the basecamp for all the calls for the projects.
|
|
The Creation and Deletion functions will likely be put into different files after some time.
|
|
For now, each function needs to be selected below.
|
|
|
|
*********
|
|
Questions:
|
|
- Does creating an attempt also create an enrollment?
|
|
- Does an attempt/enrollment create a course?
|
|
- No to either of these.
|
|
- What is the point of multiple item_ids? They seem as variable as projects.
|
|
- What is a display name in enrollment or attempt resources?
|
|
|
|
Notes:
|
|
- If client delivers just course progress, do we call completed activities in the array 1, 2, and 3.
|
|
- 427 within completed activities shows id, 281 within completed activities shows UUID.
|
|
"""
|
|
|
|
import json
|
|
from utils import calls, apikeys
|
|
|
|
JSONDOC = "./api_docs.json"
|
|
BASEURL = "https://api.northpass.com/v2/migration"
|
|
|
|
# All possible URLs and their functions:
|
|
tupee = [
|
|
# *************************
|
|
# The most fundamental of calls.
|
|
# *************************
|
|
("/v2/migration/projects", "get", "post"),
|
|
("/v2/migration/projects/{project_id}", "get", "delete", "patch"),
|
|
("/v2/migration/projects/{project_id}/items", "get", "post"),
|
|
("/v2/migration/projects/{project_id}/items/{item_id}", "get", "delete"),
|
|
# *************************
|
|
# Get Resources (Done after you've added them from below)
|
|
# *************************
|
|
("/v2/migration/projects/{project_id}/items/{item_id}/resources", "get"),
|
|
|
|
# *************************
|
|
# Post calls for creating new resources.
|
|
# *************************
|
|
("/v2/migration/projects/{project_id}/items/{item_id}/section_resources", "post"),
|
|
("/v2/migration/projects/{project_id}/items/{item_id}/person_resources", "post"),
|
|
("/v2/migration/projects/{project_id}/items/{item_id}/process_resources", "post"),
|
|
("/v2/migration/projects/{project_id}/items/{item_id}/course_resources", "post"),
|
|
(
|
|
"/v2/migration/projects/{project_id}/items/{item_id}/quiz_attempt_resources",
|
|
"post",
|
|
),
|
|
(
|
|
"/v2/migration/projects/{project_id}/items/{item_id}/activity_resources",
|
|
"post",
|
|
),
|
|
(
|
|
"/v2/migration/projects/{project_id}/items/{item_id}/course_attempt_resources",
|
|
"post",
|
|
),
|
|
(
|
|
"/v2/migration/projects/{project_id}/items/{item_id}/enrollment_resources",
|
|
"post",
|
|
),
|
|
(
|
|
"/v2/migration/projects/{project_id}/items/{item_id}/learning_path_attempt_resources",
|
|
"post",
|
|
),
|
|
# *************************
|
|
# This is just for setting up the Skilljar Config. Not needed yeet.
|
|
# *************************
|
|
(
|
|
"/v2/migration/projects/{project_id}/skilljar_configuration",
|
|
"get",
|
|
"post",
|
|
"delete",
|
|
"patch",
|
|
),
|
|
# *************************
|
|
# Extract is just for getting things out of Skilljar
|
|
# *************************
|
|
("/v2/migration/projects/{project_id}/extraction_processes", "get"),
|
|
("/v2/migration/projects/{project_id}/extract_course_attempts", "post"),
|
|
("/v2/migration/projects/{project_id}/extract_courses", "post"),
|
|
("/v2/migration/projects/{project_id}/extract_enrollments", "post"),
|
|
("/v2/migration/projects/{project_id}/extract_people", "post"),
|
|
(
|
|
"/v2/migration/projects/{project_id}/extraction_processes/{extraction_process_id}/processing_logs",
|
|
"get",
|
|
),
|
|
# *************************
|
|
# Migrate is putting things into CE.
|
|
# *************************
|
|
("/v2/migration/projects/{project_id}/start_migration", "post"),
|
|
]
|
|
|
|
|
|
def read_json_docs():
|
|
file = open(JSONDOC)
|
|
data = json.load(file)
|
|
for items, vals in data["paths"].items():
|
|
print(items)
|
|
for cmds in vals:
|
|
print(cmds)
|
|
file.close()
|
|
|
|
|
|
def create_project():
|
|
"""
|
|
Function to create a project with just a name. While ID is in the example payload, it isn't needed.
|
|
Will generate a project ID for you in the return that you can use to transfer everything.
|
|
Note that it will not give you an error if a project already exists with that name!
|
|
"""
|
|
project_name = ""
|
|
payload = {
|
|
"data": {
|
|
"type": "migration_projects",
|
|
"attributes": {"name": project_name},
|
|
}
|
|
}
|
|
url = f"{BASEURL}/projects"
|
|
Calls.post(url, payload)
|
|
|
|
|
|
def get_all_projects():
|
|
"""
|
|
Returns all projects.
|
|
"""
|
|
project_ids = []
|
|
url = f"{BASEURL}/projects"
|
|
ret = calls.get(url)
|
|
|
|
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
|
|
|
|
def delete_all_projects():
|
|
"""
|
|
Deletes all projects after returning the uuids of the projects currently available.
|
|
"""
|
|
project_ids = get_all_projects()
|
|
for proj in project_ids:
|
|
url = f"{BASEURL}/projects/{proj}"
|
|
calls.delete(url)
|
|
|
|
def get_specific_project():
|
|
"""
|
|
Returns results from a specific project.
|
|
"""
|
|
proj_id = "13aa7aed-3fb5-4488-9185-3befd0c1ae86"
|
|
url = f"{BASEURL}/projects/{proj_id}"
|
|
calls.get(url)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# delete_all_projects()
|
|
# read_json_docs()
|
|
# create_project()
|
|
get_all_projects()
|
|
# get_specific_project()
|