Migration work for Luma but the darn enrollments endpoint is still giving me issues.
This commit is contained in:
@ -1,3 +1,23 @@
|
|||||||
Completion Date,Email Address,Course Name
|
Completion Date,Email Address,Course Name
|
||||||
2024-04-19,norm@rsmsn.co,This is War
|
2019-01-11,kmillard@lumafintech.com,MassMutual Ascend: American Freedom Stars&Stripes5
|
||||||
2024-04-20,norm@rsmsn.co,This is War
|
2019-01-11,kmillard@lumafintech.com,MassMutual Ascend: American Freedom Aspire Series
|
||||||
|
2019-01-11,kmillard@lumafintech.com,MassMutual Ascend: Assurance Select Series
|
||||||
|
2021-07-15,emma@wedbush.com,Prosperity Life Group - S.USA - Safe Solution Agent Training - TD Bank
|
||||||
|
2019-11-06,emma@wedbush.com,Prosperity Life Group - SBLI - Safe Solution Agent Training - TD Bank (New York)
|
||||||
|
2021-12-01,emma@wedbush.com,Prosperity Life Group - S.USA - Select Choice Plus Agent Training
|
||||||
|
2023-04-17,emma@wedbush.com,Prosperity Life Group - SBLI - Select Choice Plus Agent Training (NY & NH Only)
|
||||||
|
2021-07-07,emma@wedbush.com,The Standard - Product Training for TD Bank
|
||||||
|
2021-07-15,emma@wedbush.com,F&G - SecureBuilder Training
|
||||||
|
2021-07-15,emma@wedbush.com,F&G - SecureIncome 7 Training
|
||||||
|
2021-07-07,emma@wedbush.com,F&G - Secure MYGA Training (Combined)
|
||||||
|
2024-04-10,emma@wedbush.com,F&G - Secure Landing Product Training
|
||||||
|
2021-07-07,emma@wedbush.com,MassMutual Ascend: Assurance Select Series
|
||||||
|
2021-07-07,emma@wedbush.com,MassMutual Ascend: American Freedom Aspire Series
|
||||||
|
2021-07-07,emma@wedbush.com,MassMutual Ascend: American Freedom Stars&Stripes5
|
||||||
|
2023-06-26,emma@wedbush.com,Western & Southern - IncomeSource January 2023
|
||||||
|
2023-06-26,emma@wedbush.com,Western & Southern - Indextra (Feb 2023)
|
||||||
|
2023-06-26,emma@wedbush.com,Western & Southern - W&S Deferred Income Annuity (IncomeSource Select) Jan 2023
|
||||||
|
2023-06-26,emma@wedbush.com,Western Southern - W&S Single Premium Deferred Annuity (SmartSelect) (January 2023)
|
||||||
|
2016-09-02,emma@wedbush.com,Symetra - Advantage Income Immediate Annuity
|
||||||
|
2022-11-17,emma@wedbush.com,Symetra - Edge Elite Enhanced Fixed Indexed
|
||||||
|
2022-11-17,emma@wedbush.com,Symetra - Select Pro and Select Max
|
||||||
|
|||||||
|
@ -13,6 +13,7 @@ import manage_csv
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
import uuid
|
import uuid
|
||||||
import json
|
import json
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
baseurl = calls.BASEURL
|
baseurl = calls.BASEURL
|
||||||
|
|
||||||
@ -78,12 +79,14 @@ def get_people(email):
|
|||||||
|
|
||||||
|
|
||||||
def get_courses(course):
|
def get_courses(course):
|
||||||
url = f"{baseurl}/courses?filter[name][eq]={course}"
|
print(f"LOOKING FOR COURSE {course}")
|
||||||
|
encoded_course = quote(course)
|
||||||
|
url = f"{baseurl}/courses?filter[name][eq]={encoded_course}"
|
||||||
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"]
|
||||||
print(f"Cool. Course {course_uuid} exists.")
|
print(f"Cool. Course {course_uuid} - {course_name} exists.")
|
||||||
return course_uuid
|
return course_uuid
|
||||||
|
|
||||||
|
|
||||||
@ -148,9 +151,6 @@ def create_enrollment_payload(course_uuid, learner_uuid, date_str):
|
|||||||
}
|
}
|
||||||
minienroll_loads.append(mini_enrollment_payload)
|
minienroll_loads.append(mini_enrollment_payload)
|
||||||
enrollment_payload = {"data": minienroll_loads }
|
enrollment_payload = {"data": minienroll_loads }
|
||||||
with open("payload.json", "w") as f:
|
|
||||||
f.write(str(enrollment_payload))
|
|
||||||
print(enrollment_payload)
|
|
||||||
return enrollment_payload
|
return enrollment_payload
|
||||||
|
|
||||||
|
|
||||||
@ -226,4 +226,4 @@ if __name__ == "__main__":
|
|||||||
print(items)
|
print(items)
|
||||||
print(probject)
|
print(probject)
|
||||||
get_data()
|
get_data()
|
||||||
start_migration()
|
# start_migration()
|
||||||
|
|||||||
258
Scripts/Migration_tool/Luma_mass_completions/mark_course_two.py
Normal file
258
Scripts/Migration_tool/Luma_mass_completions/mark_course_two.py
Normal file
@ -0,0 +1,258 @@
|
|||||||
|
"""
|
||||||
|
Order of operations:
|
||||||
|
1. Get input of people and course
|
||||||
|
2. Create Project
|
||||||
|
3. Create Item with Course_attempt type
|
||||||
|
4. Create Course Attempt Resource with the same type.
|
||||||
|
5. Start Migration.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from sys import argv
|
||||||
|
from utils import calls
|
||||||
|
import manage_csv
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
import uuid
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
|
baseurl = calls.BASEURL
|
||||||
|
|
||||||
|
probject = {}
|
||||||
|
items = {}
|
||||||
|
courses = {}
|
||||||
|
people = {}
|
||||||
|
miniattempt_loads = []
|
||||||
|
minienroll_loads = []
|
||||||
|
|
||||||
|
|
||||||
|
item_types = [
|
||||||
|
"courses",
|
||||||
|
"sections",
|
||||||
|
"activities",
|
||||||
|
"people",
|
||||||
|
"enrollment_resources",
|
||||||
|
"course_attempts",
|
||||||
|
"quiz_attempts",
|
||||||
|
"certificates",
|
||||||
|
"learning_path_attempts",
|
||||||
|
]
|
||||||
|
project_name = argv[1]
|
||||||
|
|
||||||
|
def get_data():
|
||||||
|
|
||||||
|
print()
|
||||||
|
print("Getting Data")
|
||||||
|
|
||||||
|
df = manage_csv.import_as_dataframe()
|
||||||
|
df.columns = df.columns.str.lower()
|
||||||
|
# row_iterator = df.iterrows()
|
||||||
|
# _, last = next(row_iterator)
|
||||||
|
for i, row in df.iterrows():
|
||||||
|
email = row["email address"]
|
||||||
|
course = row["course name"]
|
||||||
|
date = row["completion date"]
|
||||||
|
people_tuple = get_people(email)
|
||||||
|
if people_tuple is None:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
course_uuid = get_courses(course)
|
||||||
|
attempt_payload = create_attempt_payload(course_uuid, people_tuple[0], date)
|
||||||
|
enrollment_payload = create_enrollment_payload(
|
||||||
|
course_uuid, people_tuple[0], date
|
||||||
|
)
|
||||||
|
|
||||||
|
create_attempt_resource(attempt_payload)
|
||||||
|
print()
|
||||||
|
print(f"On to Enrollments resource...")
|
||||||
|
print()
|
||||||
|
create_enrollment_resource(enrollment_payload)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_people(email):
|
||||||
|
print()
|
||||||
|
print(f"Getting People for {email}")
|
||||||
|
url = f"{baseurl}/people?filter[email][eq]={email}"
|
||||||
|
returned = calls.get(url)
|
||||||
|
if returned["data"] == []:
|
||||||
|
print("I couldn't find this user.")
|
||||||
|
else:
|
||||||
|
for api_items in returned["data"]:
|
||||||
|
if api_items["attributes"]["registration_status"] == "activated":
|
||||||
|
single_uuid = api_items["id"]
|
||||||
|
single_email = api_items["attributes"]["email"]
|
||||||
|
print(f"Cool. Person {single_uuid} exists.")
|
||||||
|
return (single_uuid, single_email)
|
||||||
|
else:
|
||||||
|
print(f"Person not found or activated. {email}")
|
||||||
|
|
||||||
|
|
||||||
|
def get_courses(course):
|
||||||
|
print()
|
||||||
|
print(f"Getting Courses for {course}")
|
||||||
|
encoded_course = quote(course)
|
||||||
|
url = f"{baseurl}/courses?filter[name][eq]={encoded_course}"
|
||||||
|
returned = calls.get(url)
|
||||||
|
for items in returned["data"]:
|
||||||
|
course_uuid = items["id"]
|
||||||
|
course_name = items["attributes"]["name"]
|
||||||
|
print(f"Cool. Course {course_uuid} exists.")
|
||||||
|
return course_uuid
|
||||||
|
|
||||||
|
|
||||||
|
def create_attempt_payload(course_uuid, learner_uuid, date_str):
|
||||||
|
print()
|
||||||
|
print(f"Creating Course Attempt Payload")
|
||||||
|
now = datetime.now()
|
||||||
|
date_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
if type(date_str) == str:
|
||||||
|
if len(date_str) >= 8 and len(date_str) <= 10:
|
||||||
|
date_str = f"{date_str} 00:00:00"
|
||||||
|
formatted_date = datetime.strptime(date_str, date_format)
|
||||||
|
formatted_date = str(formatted_date)
|
||||||
|
else:
|
||||||
|
formatted_date = datetime.strptime(date_str, date_format)
|
||||||
|
formatted_date = str(formatted_date)
|
||||||
|
mini_attempt_payload = {
|
||||||
|
"type": "course_attempt_resources",
|
||||||
|
"attributes": {
|
||||||
|
"uuid": str(uuid.uuid4()),
|
||||||
|
"display_name": f"{learner_uuid}s Attempt for course {course_uuid}",
|
||||||
|
"data": {
|
||||||
|
"learner_id": f"{learner_uuid}",
|
||||||
|
"course_id": f"{course_uuid}",
|
||||||
|
"progress": 100,
|
||||||
|
"enrolled_at": formatted_date,
|
||||||
|
"started_at": formatted_date,
|
||||||
|
"completed_at": formatted_date,
|
||||||
|
"completed_activities": [
|
||||||
|
{"id": str(uuid.uuid4()), "completed_at": formatted_date}
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
miniattempt_loads.append(mini_attempt_payload)
|
||||||
|
attempt_payload = { "data": miniattempt_loads }
|
||||||
|
#print(attempt_payload)
|
||||||
|
return attempt_payload
|
||||||
|
|
||||||
|
|
||||||
|
def create_enrollment_payload(course_uuid, learner_uuid, date_str):
|
||||||
|
print()
|
||||||
|
print(f"Creating Course Enrollment Payload")
|
||||||
|
now = datetime.now()
|
||||||
|
date_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
if type(date_str) == str:
|
||||||
|
if len(date_str) >= 8 and len(date_str) <= 10:
|
||||||
|
date_str = f"{date_str} 00:00:00"
|
||||||
|
formatted_date = datetime.strptime(date_str, date_format)
|
||||||
|
formatted_date = str(formatted_date)
|
||||||
|
else:
|
||||||
|
formatted_date = datetime.strptime(date_str, date_format)
|
||||||
|
formatted_date = str(formatted_date)
|
||||||
|
mini_enrollment_payload = {
|
||||||
|
"type": "enrollment_resource",
|
||||||
|
"attributes": {
|
||||||
|
"uuid": str(uuid.uuid4()),
|
||||||
|
"display_name": f"{learner_uuid}s enrollment for course {course_uuid}",
|
||||||
|
"data": {
|
||||||
|
"enrolled_at": formatted_date,
|
||||||
|
"course_id": course_uuid,
|
||||||
|
"learner_id": learner_uuid
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
minienroll_loads.append(mini_enrollment_payload)
|
||||||
|
enrollment_payload = {"data": minienroll_loads }
|
||||||
|
with open("payload.json", "w") as f:
|
||||||
|
f.write(str(enrollment_payload))
|
||||||
|
#print(enrollment_payload)
|
||||||
|
return enrollment_payload
|
||||||
|
|
||||||
|
|
||||||
|
def create_enrollment_resource(enrollment_payload):
|
||||||
|
print()
|
||||||
|
print("Creating Enrollment Resource")
|
||||||
|
item = items["enrollments"]
|
||||||
|
enrollment_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item}/enrollment_resources"
|
||||||
|
print(enrollment_url)
|
||||||
|
#print(f"Enrollment Payload is: {enrollment_payload}")
|
||||||
|
enrollment_call = calls.post(enrollment_url, enrollment_payload)
|
||||||
|
print(
|
||||||
|
f"In trying the enrollment resource, the following code was returned: {enrollment_call.status_code}"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_attempt_resource(attempt_payload):
|
||||||
|
print()
|
||||||
|
print("Creating Attempt Resource")
|
||||||
|
item = items["course_attempts"]
|
||||||
|
attempt_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item}/course_attempt_resources"
|
||||||
|
print(attempt_url)
|
||||||
|
#print(f"Attempt Payload is: {attempt_payload}")
|
||||||
|
attempt_call = calls.post(attempt_url, attempt_payload)
|
||||||
|
print(f"Attempt resource created successfully with status code: {attempt_call.status_code}")
|
||||||
|
# Status code 201 means the resource was created successfully
|
||||||
|
if attempt_call.status_code != 201:
|
||||||
|
print(f"Warning: Unexpected status code: {attempt_call.status_code}")
|
||||||
|
|
||||||
|
def create_project(project_name):
|
||||||
|
print()
|
||||||
|
print("Creating Project")
|
||||||
|
proj_payload = {
|
||||||
|
"data": {
|
||||||
|
"type": "migration_projects",
|
||||||
|
"attributes": {"name": project_name},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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}")
|
||||||
|
|
||||||
|
|
||||||
|
def create_item(i_type):
|
||||||
|
print()
|
||||||
|
print("Creating Item")
|
||||||
|
# Item Type Options: 'courses', 'sections', 'activities', 'people', 'enrollments', 'course_attempts', 'quiz_attempts', 'certificates', 'learning_path_attempts'
|
||||||
|
item_full_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items"
|
||||||
|
item_type = i_type
|
||||||
|
print(item_type)
|
||||||
|
item_payload = {
|
||||||
|
"data": {
|
||||||
|
"attributes": {"type": item_type},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# "type": "migration_items",
|
||||||
|
item_return = calls.post(item_full_url, item_payload)
|
||||||
|
items[item_type] = item_return["data"]["id"]
|
||||||
|
item_id = item_return["data"]["id"]
|
||||||
|
print(f"Created Item ID: { items[item_type] }")
|
||||||
|
return item_id
|
||||||
|
|
||||||
|
|
||||||
|
def start_migration():
|
||||||
|
print()
|
||||||
|
print("Starting Migration Function")
|
||||||
|
start_url = (
|
||||||
|
f"{baseurl}/migration/projects/{list(probject.values())[0]}/start_migration"
|
||||||
|
)
|
||||||
|
empty = ""
|
||||||
|
mig = calls.post(start_url, empty)
|
||||||
|
print(mig.text)
|
||||||
|
print(mig)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
create_project(project_name)
|
||||||
|
create_item("course_attempts")
|
||||||
|
create_item("enrollments")
|
||||||
|
print()
|
||||||
|
print("Items: ")
|
||||||
|
print(items)
|
||||||
|
print()
|
||||||
|
print("Project: ")
|
||||||
|
print(probject)
|
||||||
|
get_data()
|
||||||
|
#start_migration()
|
||||||
|
print(f"Done.")
|
||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@ -1 +1,2 @@
|
|||||||
SANDBOX = "SlpQlju219WnWogn94dQUT6Yt"
|
SANDBOX = "SlpQlju219WnWogn94dQUT6Yt"
|
||||||
|
LUMA = "oDFA7XSmjEKjEwIDIKLm0rxs1"
|
||||||
|
|||||||
@ -5,7 +5,7 @@ from json import JSONDecodeError
|
|||||||
|
|
||||||
|
|
||||||
PP = pprint.PrettyPrinter(indent=4)
|
PP = pprint.PrettyPrinter(indent=4)
|
||||||
APIKEY = apikeys.SANDBOX
|
APIKEY = apikeys.LUMA
|
||||||
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"
|
||||||
|
|
||||||
@ -20,7 +20,6 @@ def get(url):
|
|||||||
)
|
)
|
||||||
finally:
|
finally:
|
||||||
json_get = get_response.json()
|
json_get = get_response.json()
|
||||||
# PP.pprint(json_get)
|
|
||||||
return json_get
|
return json_get
|
||||||
|
|
||||||
|
|
||||||
@ -35,7 +34,6 @@ def post(url, payload):
|
|||||||
print(f"Status code is {post_response.status_code}")
|
print(f"Status code is {post_response.status_code}")
|
||||||
json_post = post_response.json()
|
json_post = post_response.json()
|
||||||
if json_post:
|
if json_post:
|
||||||
print(json_post)
|
|
||||||
return json_post
|
return json_post
|
||||||
else:
|
else:
|
||||||
return post_response
|
return post_response
|
||||||
|
|||||||
Reference in New Issue
Block a user