TONS of migration progress! I'm so close
...
This commit is contained in:
Binary file not shown.
@ -4,7 +4,7 @@ from pathlib import Path
|
|||||||
import Apikeys
|
import Apikeys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
basefile = "/Users/normrasmussen/Downloads/mizuno-july-completions.csv"
|
basefile = "/Users/normrasmussen/Downloads/mizuno-aug2024-completions.csv"
|
||||||
api_key = Apikeys.MIZUNO
|
api_key = Apikeys.MIZUNO
|
||||||
uuid_url = "https://api.northpass.com/v2/people?filter[email][eq]="
|
uuid_url = "https://api.northpass.com/v2/people?filter[email][eq]="
|
||||||
prop_url = "https://api.northpass.com/v2/properties/people/"
|
prop_url = "https://api.northpass.com/v2/properties/people/"
|
||||||
@ -51,7 +51,7 @@ def load_file(basefile):
|
|||||||
completions = completions[completions["userid"] != "0"]
|
completions = completions[completions["userid"] != "0"]
|
||||||
# completions = completions.iloc[:, 0:]
|
# completions = completions.iloc[:, 0:]
|
||||||
completions.to_csv(
|
completions.to_csv(
|
||||||
"/Users/normrasmussen/Downloads/Mizuno-July2024-with-PGAID.csv",
|
"/Users/normrasmussen/Downloads/Mizuno-August2024-with-PGAID.csv",
|
||||||
index=False,
|
index=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ HEADERS = {
|
|||||||
"X-Api-Key": APIKEY,
|
"X-Api-Key": APIKEY,
|
||||||
}
|
}
|
||||||
BASEURL = "https://api.northpass.com/v2/"
|
BASEURL = "https://api.northpass.com/v2/"
|
||||||
IMPORTFILE = "/Users/normrasmussen/Downloads/bloomerang-mass-import.csv"
|
IMPORTFILE = "/Users/normrasmussen/Downloads/bloomberg-vms-invite.csv"
|
||||||
|
|
||||||
|
|
||||||
def bulk_invite_and_group():
|
def bulk_invite_and_group():
|
||||||
|
|||||||
Binary file not shown.
@ -1,7 +1,7 @@
|
|||||||
import Calls
|
from utils import calls
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
baseurl = Calls.BASEURL
|
baseurl = calls.BASEURL
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Order of operations:
|
Order of operations:
|
||||||
@ -59,12 +59,22 @@ Order of operations:
|
|||||||
# "joe schmo": "5555555"
|
# "joe schmo": "5555555"
|
||||||
# }
|
# }
|
||||||
# }
|
# }
|
||||||
probject = {
|
probject = {}
|
||||||
"items": {},
|
items = {}
|
||||||
"courses": {},
|
courses = {}
|
||||||
"people" : {}
|
people = {}
|
||||||
}
|
|
||||||
ITEM_TYPES = ['courses', 'sections', 'activities', 'people', 'enrollments', 'course_attempts', 'quiz_attempts', 'certificates', 'learning_path_attempts']
|
ITEM_TYPES = [
|
||||||
|
"courses",
|
||||||
|
"sections",
|
||||||
|
"activities",
|
||||||
|
"people",
|
||||||
|
"enrollments",
|
||||||
|
"course_attempts",
|
||||||
|
"quiz_attempts",
|
||||||
|
"certificates",
|
||||||
|
"learning_path_attempts",
|
||||||
|
]
|
||||||
|
|
||||||
PPL_URL = "people"
|
PPL_URL = "people"
|
||||||
COURSE_URL = "courses"
|
COURSE_URL = "courses"
|
||||||
@ -78,7 +88,7 @@ def get_people():
|
|||||||
learner = get_individual_person(email)
|
learner = get_individual_person(email)
|
||||||
ppl_uuid = learner[0]
|
ppl_uuid = learner[0]
|
||||||
ppl_email = learner[1]
|
ppl_email = learner[1]
|
||||||
probject["people"][ppl_email] = ppl_uuid
|
people[ppl_email] = ppl_uuid
|
||||||
get_courses(ppl_uuid)
|
get_courses(ppl_uuid)
|
||||||
elif type(email) is list:
|
elif type(email) is list:
|
||||||
person_uuids = get_group_person(email)
|
person_uuids = get_group_person(email)
|
||||||
@ -98,71 +108,95 @@ def get_courses(learner_uuid):
|
|||||||
|
|
||||||
def get_individual_course(name, learner_uuid):
|
def get_individual_course(name, learner_uuid):
|
||||||
url = f"{baseurl}/courses?filter[name][eq]={name}"
|
url = f"{baseurl}/courses?filter[name][eq]={name}"
|
||||||
returned = Calls.get(url)
|
returned = calls.get(url)
|
||||||
|
|
||||||
for items in returned["data"]:
|
for items in returned["data"]:
|
||||||
course_uuid = items["id"]
|
course_uuid = items["id"]
|
||||||
course_name = items["attributes"]["name"]
|
course_name = items["attributes"]["name"]
|
||||||
probject["courses"][course_name] = course_uuid
|
courses[course_name] = course_uuid
|
||||||
print(f"Cool. Course {course_uuid} exists. Checking enrollments.")
|
print(f"Cool. Course {course_uuid} exists. Checking enrollments.")
|
||||||
# enrollment = get_enrollment_status(course_uuid, learner_uuid)
|
enrollment = get_enrollment_status(course_uuid, learner_uuid)
|
||||||
|
|
||||||
# Use this to get a specific value from the courses sub-dict
|
# Use this to get a specific value from the courses sub-dict
|
||||||
print(list(probject["people"].values())[0])
|
|
||||||
|
|
||||||
|
|
||||||
def get_enrollment_status(uuid, learner_uuid):
|
def get_enrollment_status(uuid, learner_uuid):
|
||||||
enrollment_url = (
|
enrollment_url = (
|
||||||
f"{baseurl}/courses/{uuid}/enrollments?filter[person_id][eq]={learner_uuid}"
|
f"{baseurl}/courses/{uuid}/enrollments?filter[person_id][eq]={learner_uuid}"
|
||||||
)
|
)
|
||||||
enrolled = Calls.get(enrollment_url)
|
enrolled = calls.get(enrollment_url)
|
||||||
print(enrolled["data"])
|
|
||||||
if enrolled["data"] == []:
|
if enrolled["data"] == []:
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
print("Oof, no enrollments. Not to worry. We'll get one created for you.")
|
print("Oof, no enrollments. Not to worry. We'll get one created for you.")
|
||||||
mig_enroll_payload = {
|
mig_enroll_payload = {
|
||||||
"data": {
|
"data": [
|
||||||
"attributes": {
|
{
|
||||||
{"enrolled_at": formatted_now},
|
"type": f"{ list(items.keys())[0] }",
|
||||||
{"course_id": uuid},
|
"attributes": {
|
||||||
{"person_id": learner_uuid},
|
"uuid": f"{ list(items.values())[0] }",
|
||||||
|
"display_name": "Enrollment to Course 1",
|
||||||
|
"data": {
|
||||||
|
"enrolled_at": formatted_now,
|
||||||
|
"course_id": f"{ list(courses.values())[0] }",
|
||||||
|
"person_id": f"{ list(people.values())[0] }"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
mig_enroll_url = Calls.post(
|
mig_enroll_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/enrollment_resources"
|
||||||
f"{baseurl}migration/projects/{probject}/items/{item_id}/enrollment_resources",
|
mig_enroll = calls.post(mig_enroll_url, mig_enroll_payload)
|
||||||
mig_enroll_payload,
|
|
||||||
)
|
|
||||||
print("Cool, enrollment resource has been created. Let's check that it exists.")
|
print("Cool, enrollment resource has been created. Let's check that it exists.")
|
||||||
check_resources()
|
resource_check = check_resources()
|
||||||
|
if resource_check['data'] != []:
|
||||||
|
print("We're in! Enrollment confirmed. Let's create an attempt")
|
||||||
|
create_attempt()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Nice! We have an enrollment. So now we just need to update progress.")
|
print("Nice! We have an enrollment. So now we just need to update progress.")
|
||||||
# create_attempt(enrolled["data"])
|
create_attempt(mig_enroll_url["data"])
|
||||||
|
|
||||||
|
|
||||||
def create_attempt(data):
|
def check_item(itype):
|
||||||
print(f"Is there a project ID? {PROJ_ID}")
|
if itype not in items:
|
||||||
attempt_url = f"{baseurl}/migration/projects/{PROJ_ID}/items/{ITEM_ID}/course_attempt_resources"
|
create_item(i_type= "attempts")
|
||||||
now = datetime.now()
|
print(f"Is there a project ID? {list(probject.values())[0]}")
|
||||||
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
attempt_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/course_attempt_resources"
|
||||||
new_attempt_payload = {
|
print(attempt_url)
|
||||||
"data": {
|
now = datetime.now()
|
||||||
"attributes": {
|
formatted_now = now.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
"uuid": {"which uuid?"},
|
new_attempt_payload = { "data": [
|
||||||
"display_name": {f"{PPL_EMAIL}'s Attempt for course {COURSE_NAME}"},
|
{
|
||||||
"learner_id": {PPL_UUID},
|
"type": "attempts",
|
||||||
"course_id": {COURSE_UUID},
|
"attributes": {
|
||||||
"progress": {"100"},
|
"uuid": "1234567890",
|
||||||
"started_at": {datetime.now() - timedelta(hours=2)},
|
"display_name": f"{list(people.keys())[0]}'s Attempt for course {list(courses.keys())[0]}",
|
||||||
"completed_at": {formatted_now},
|
"data": {
|
||||||
"completed_activities": [
|
"learner_id": f"{list(people.keys())[0]}",
|
||||||
{"uuid": {"1111"}, "completed_at": {formatted_now}}
|
"course_id": f"{list(courses.values())[0]}",
|
||||||
],
|
"progress": "100",
|
||||||
|
"started_at": f"{datetime.now() - timedelta(hours=2)}",
|
||||||
|
"enrolled_at": f"{datetime.now() - timedelta(hours=3)}",
|
||||||
|
"completed_at": formatted_now,
|
||||||
|
"completed_activities": [
|
||||||
|
{
|
||||||
|
"uuid": "1111",
|
||||||
|
"completed_at": formatted_now
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
check_resources()
|
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)
|
||||||
|
print("**********")
|
||||||
|
print(f"MigAttemptURL")
|
||||||
|
print(mig_attempt_call)
|
||||||
|
print("**********")
|
||||||
|
check_resources()
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -177,49 +211,46 @@ def create_attempt(data):
|
|||||||
def check_resources():
|
def check_resources():
|
||||||
print("Checking resources")
|
print("Checking resources")
|
||||||
get_resources_url = (
|
get_resources_url = (
|
||||||
f"{baseurl}/migration/projects/{PROJ_ID}/items/{ITEM_ID}/resources"
|
f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{list(items.values())[0]}/resources"
|
||||||
)
|
)
|
||||||
get_resources = Calls.get(get_resources_url)
|
get_resources = calls.get(get_resources_url)
|
||||||
if get_resources["data"] == []:
|
if get_resources["data"] == []:
|
||||||
print("Something went wrong. No resources were created.")
|
print("Something went wrong. No resources were created.")
|
||||||
else:
|
else:
|
||||||
print("We're in! Here's the data:")
|
return get_resources
|
||||||
print(get_resources)
|
|
||||||
|
|
||||||
|
|
||||||
def create_project():
|
def create_project():
|
||||||
project_name = "Testing Project 2"
|
project_name = "Testing Project 2"
|
||||||
proj_payload = {
|
proj_payload = {
|
||||||
"data":
|
"data": {
|
||||||
{
|
|
||||||
"type": "migration_projects",
|
"type": "migration_projects",
|
||||||
"attributes": {"name": project_name},
|
"attributes": {"name": project_name},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
proj_full_url = f"{baseurl}/migration/{PROJ_URL}"
|
proj_full_url = f"{baseurl}/migration/{PROJ_URL}"
|
||||||
tmp_p = Calls.post(proj_full_url, proj_payload)
|
tmp_p = calls.post(proj_full_url, proj_payload)
|
||||||
probject[project_name] = tmp_p["data"]["id"]
|
probject[project_name] = tmp_p["data"]["id"]
|
||||||
print(f"Created Project: {probject}")
|
print(f"Created Project: {probject}")
|
||||||
i_type = "enrollments"
|
i_type = "enrollments"
|
||||||
create_item(i_type, project_name)
|
create_item(i_type)
|
||||||
|
|
||||||
def create_item(i_type, project_name):
|
|
||||||
print(project_name)
|
def create_item(i_type):
|
||||||
# Item Type Options: 'courses', 'sections', 'activities', 'people', 'enrollments', 'course_attempts', 'quiz_attempts', 'certificates', 'learning_path_attempts'
|
# Item Type Options: 'courses', 'sections', 'activities', 'people', 'enrollments', 'course_attempts', 'quiz_attempts', 'certificates', 'learning_path_attempts'
|
||||||
item_full_url = f"{baseurl}/migration/{PROJ_URL}/{probject[project_name]}/{ITEM_URL}"
|
item_full_url = (
|
||||||
|
f"{baseurl}/migration/{PROJ_URL}/{list(probject.values())[0]}/{ITEM_URL}"
|
||||||
|
)
|
||||||
item_type = i_type
|
item_type = i_type
|
||||||
item_payload = {
|
item_payload = {
|
||||||
"data":
|
"data": {
|
||||||
{
|
|
||||||
"type": "migration_items",
|
"type": "migration_items",
|
||||||
"attributes": {
|
"attributes": {"type": item_type},
|
||||||
"type": item_type
|
}
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
item_return = Calls.post(item_full_url, item_payload)
|
item_return = calls.post(item_full_url, item_payload)
|
||||||
probject['items'][item_type] = item_return["data"]["id"]
|
items[item_type] = item_return["data"]["id"]
|
||||||
print(f"Created Item ID: { probject['items'][item_type] }")
|
print(f"Created Item ID: { items[item_type] }")
|
||||||
print(probject)
|
print(probject)
|
||||||
|
|
||||||
|
|
||||||
@ -227,7 +258,7 @@ def get_group_course(list):
|
|||||||
multiple_uuids = []
|
multiple_uuids = []
|
||||||
for person in email:
|
for person in email:
|
||||||
url = f"{baseurl}/people?filter[email][eq]={email}"
|
url = f"{baseurl}/people?filter[email][eq]={email}"
|
||||||
returned = Calls.get(url)
|
returned = calls.get(url)
|
||||||
|
|
||||||
for items in returned["data"]:
|
for items in returned["data"]:
|
||||||
multiple_uuids.append(learner_uuid)
|
multiple_uuids.append(learner_uuid)
|
||||||
@ -235,7 +266,7 @@ def get_group_course(list):
|
|||||||
|
|
||||||
def get_individual_person(email):
|
def get_individual_person(email):
|
||||||
url = f"{baseurl}/people?filter[email][eq]={email}"
|
url = f"{baseurl}/people?filter[email][eq]={email}"
|
||||||
returned = Calls.get(url)
|
returned = calls.get(url)
|
||||||
|
|
||||||
for items in returned["data"]:
|
for items in returned["data"]:
|
||||||
if items["attributes"]["registration_status"] == "activated":
|
if items["attributes"]["registration_status"] == "activated":
|
||||||
@ -253,7 +284,7 @@ def get_group_person(list):
|
|||||||
multiple_uuids = []
|
multiple_uuids = []
|
||||||
for person in email:
|
for person in email:
|
||||||
url = f"{baseurl}/people?filter[email][eq]={email}"
|
url = f"{baseurl}/people?filter[email][eq]={email}"
|
||||||
returned = Calls.get(url)
|
returned = calls.get(url)
|
||||||
|
|
||||||
for items in returned["data"]:
|
for items in returned["data"]:
|
||||||
if items["attributes"]["registration_status"] == "activated":
|
if items["attributes"]["registration_status"] == "activated":
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
SANDBOX = "SlpQlju219WnWogn94dQUT6Yt"
|
||||||
@ -1,11 +1,11 @@
|
|||||||
import requests
|
import requests
|
||||||
import Apikeys
|
from utils import apikeys
|
||||||
import pprint
|
import pprint
|
||||||
import json
|
from json import JSONDecodeError
|
||||||
|
|
||||||
|
|
||||||
PP = pprint.PrettyPrinter(indent=4)
|
PP = pprint.PrettyPrinter(indent=4)
|
||||||
APIKEY = Apikeys.SANDBOX
|
APIKEY = apikeys.SANDBOX
|
||||||
HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY}
|
HEADERS = {"content-type": "application/json", "X-Api-Key": APIKEY}
|
||||||
BASEURL = "https://api.northpass.com/v2"
|
BASEURL = "https://api.northpass.com/v2"
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ BASEURL = "https://api.northpass.com/v2"
|
|||||||
def get(url):
|
def get(url):
|
||||||
try:
|
try:
|
||||||
get_response = requests.get(url, headers=HEADERS)
|
get_response = requests.get(url, headers=HEADERS)
|
||||||
# print(f"Executed Get Request. Status code is {get_response.status_code}")
|
print(f"Executed Get Request. Status code is {get_response.status_code}")
|
||||||
except HTTPError as h:
|
except HTTPError as h:
|
||||||
print(
|
print(
|
||||||
f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}"
|
f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}"
|
||||||
@ -28,33 +28,36 @@ def post(url, payload):
|
|||||||
try:
|
try:
|
||||||
post_response = requests.post(url, headers=HEADERS, json=payload)
|
post_response = requests.post(url, headers=HEADERS, json=payload)
|
||||||
print(f"Executed Post Request. Status code is {post_response.status_code}")
|
print(f"Executed Post Request. Status code is {post_response.status_code}")
|
||||||
# if post_response.status_code == 404:
|
except TypeError as h:
|
||||||
# print(f"Received 404 Response. Here's the returned text: {post_response.text}")
|
|
||||||
except HTTPError as h:
|
|
||||||
print(
|
print(
|
||||||
f"Error occurred. Here's the info: {h} and status code: {post_response.status_code}"
|
f"Error occurred. Here's the info: {h} and status code: {post_response.status_code}"
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
try:
|
try:
|
||||||
json_post = post_response.json()
|
json_post = post_response.json()
|
||||||
# PP.pprint(json_post)
|
# print(f"JSONResponse: {json_post}")
|
||||||
return json_post
|
return json_post
|
||||||
except JSONDecodeError as j:
|
except JSONDecodeError as e:
|
||||||
print(
|
print(f"Error occurred. Here's the info: {e}.")
|
||||||
f"Error occurred. Here's the info: {h} and status code: {post_response.status_code}"
|
# print(f"PostResponse: {post_response}")
|
||||||
)
|
|
||||||
return post_response
|
return post_response
|
||||||
finally:
|
finally:
|
||||||
|
# PP.pprint(json_get)
|
||||||
pass
|
pass
|
||||||
|
#
|
||||||
|
# def post(url, payload):
|
||||||
|
# post_response = requests.post(url, headers=HEADERS, json=payload)
|
||||||
|
# print(f"Executed Post Request. Status code is {post_response.status_code}")
|
||||||
|
# print(post_response.text)
|
||||||
|
# return post_response
|
||||||
|
|
||||||
def delete(url):
|
def delete(url):
|
||||||
try:
|
try:
|
||||||
get_response = requests.delete(url, headers=HEADERS)
|
delete_response = requests.delete(url, headers=HEADERS)
|
||||||
# print(f"Executed Get Request. Status code is {get_response.status_code}")
|
print(f"Executed Delete Request. Status code is {delete_response.status_code}")
|
||||||
except HTTPError as h:
|
except HTTPError as h:
|
||||||
print(
|
print(
|
||||||
f"Error occurred. Here's the info: {h} and status code: {get_response.status_code}"
|
f"Error occurred. Here's the info: {h} and status code: {delete_response.status_code}"
|
||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
return get_response
|
return delete_response
|
||||||
Reference in New Issue
Block a user