Figured out some more migration project stuff.

This commit is contained in:
Norm Rasmussen
2024-12-05 12:28:42 -05:00
parent eb99e7aaf6
commit 0999529ffb
6 changed files with 30 additions and 42 deletions

View File

@ -1,16 +1,3 @@
Completion Date,Email Address,Course Name Completion Date,Email Address,Course Name
2024-04-19,norm@rsmsn.co,This is War 2024-04-19,norm@rsmsn.co,This is War
2024-04-20,norm+climbing@northpass.com,This is War 2024-04-20,norm@rsmsn.co,This is War
2024-04-21,gasssygas@gas.com,This is War
2024-04-22,boy@morrison.org,This is War
2024-04-23,norm+mtnclimb@northpass.com,This is War
2024-04-24,n,This is War
2024-04-25,jim@morrison.org,This is War
2024-04-25,nrasmussen+admincomms@northpass.com,This is War
2024-04-26,nrasmussen+test2@gainsight.com,This is War
2024-04-27,paulmiller@paulmiller.com,This is War
2024-04-28,potatobox@gas.com,This is War
2024-05-01,kfolsomtest@northpass.com,This is War
2024-05-02,biggum@gas.com,This is War
2024-05-03,aliens@destination.com,This is War
2024-05-04,y,This is War

1 Completion Date Email Address Course Name
2 2024-04-19 norm@rsmsn.co This is War
3 2024-04-20 norm+climbing@northpass.com norm@rsmsn.co This is War
2024-04-21 gasssygas@gas.com This is War
2024-04-22 boy@morrison.org This is War
2024-04-23 norm+mtnclimb@northpass.com This is War
2024-04-24 n This is War
2024-04-25 jim@morrison.org This is War
2024-04-25 nrasmussen+admincomms@northpass.com This is War
2024-04-26 nrasmussen+test2@gainsight.com This is War
2024-04-27 paulmiller@paulmiller.com This is War
2024-04-28 potatobox@gas.com This is War
2024-05-01 kfolsomtest@northpass.com This is War
2024-05-02 biggum@gas.com This is War
2024-05-03 aliens@destination.com This is War
2024-05-04 y This is War

View File

@ -0,0 +1,6 @@
import pandas as pd
def import_as_dataframe():
importfile = "./data.csv"
df = pd.read_csv(importfile)
return df

View File

@ -12,6 +12,7 @@ from utils import calls
import manage_csv import manage_csv
from datetime import datetime, timedelta from datetime import datetime, timedelta
import uuid import uuid
import json
baseurl = calls.BASEURL baseurl = calls.BASEURL
@ -40,12 +41,14 @@ project_name = argv[1]
def get_data(): def get_data():
df = manage_csv.import_as_dataframe() df = manage_csv.import_as_dataframe()
df.columns = df.columns.str.lower() df.columns = df.columns.str.lower()
row_iterator = df.iterrows() # row_iterator = df.iterrows()
_, last = next(row_iterator) # _, last = next(row_iterator)
for i, row in row_iterator: for i, row in df.iterrows():
email = row["email address"] email = row["email address"]
print(email)
course = row["course name"] course = row["course name"]
date = row["completion date"] date = row["completion date"]
print(date)
people_tuple = get_people(email) people_tuple = get_people(email)
if people_tuple is None: if people_tuple is None:
pass pass
@ -135,11 +138,11 @@ def create_enrollment_payload(course_uuid, learner_uuid, date_str):
"type": "enrollment_resource", "type": "enrollment_resource",
"attributes": { "attributes": {
"uuid": str(uuid.uuid4()), "uuid": str(uuid.uuid4()),
"display_name": f"{learner_uuid}s enrollment for course {course_uuid}/", "display_name": f"{learner_uuid}s enrollment for course {course_uuid}",
"data": { "data": {
"enrolled_at": formatted_date, "enrolled_at": formatted_date,
"course_id": course_uuid, "course_id": course_uuid,
"person_id": learner_uuid "learner_id": learner_uuid
} }
} }
} }
@ -167,6 +170,7 @@ def create_attempt_resource(attempt_payload):
attempt_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item}/course_attempt_resources" attempt_url = f"{baseurl}/migration/projects/{list(probject.values())[0]}/items/{item}/course_attempt_resources"
print(attempt_url) print(attempt_url)
print(f"Attempt Payload is: {attempt_payload}") print(f"Attempt Payload is: {attempt_payload}")
# attempt_payload2 = json.dumps(attempt_payload)
attempt_call = calls.post(attempt_url, attempt_payload) attempt_call = calls.post(attempt_url, attempt_payload)
print( print(
f"In trying the attempt resource, the following code was returned: {attempt_call.status_code}" f"In trying the attempt resource, the following code was returned: {attempt_call.status_code}"

View File

@ -0,0 +1 @@
{'data': [{'type': 'enrollment_resource', 'attributes': {'uuid': '70e69e72-b666-4d42-8f17-f86c635a9425', 'display_name': '101d891d-f145-4cb2-8f7f-f0d8a90a743es enrollment for course e8b40b77-26a2-468e-bf07-6c93259fe7e9', 'data': {'enrolled_at': '2024-04-19 00:00:00', 'course_id': 'e8b40b77-26a2-468e-bf07-6c93259fe7e9', 'learner_id': '101d891d-f145-4cb2-8f7f-f0d8a90a743e'}}}, {'type': 'enrollment_resource', 'attributes': {'uuid': 'c6679c4e-19e8-43ba-8666-5e48d5c9020a', 'display_name': '101d891d-f145-4cb2-8f7f-f0d8a90a743es enrollment for course e8b40b77-26a2-468e-bf07-6c93259fe7e9', 'data': {'enrolled_at': '2024-04-20 00:00:00', 'course_id': 'e8b40b77-26a2-468e-bf07-6c93259fe7e9', 'learner_id': '101d891d-f145-4cb2-8f7f-f0d8a90a743e'}}}]}

View File

@ -25,31 +25,21 @@ def get(url):
def post(url, payload): def post(url, payload):
try: request_subject = url.split("/")[-2:]
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 for {str(request_subject)}.")
except Exception as h: if str(post_response.status_code).startswith('2'):
print( print(f"Status code is {post_response.status_code}")
f"Error occurred. Here's the info: {h} and text: {post_response.text}" return post_response.json()
) else:
finally: print(f"Status code is {post_response.status_code}")
try: json_post = post_response.json()
json_post = post_response.json() if json_post:
# print(f"JSONResponse: {json_post}") print(json_post)
return json_post return json_post
except JSONDecodeError as e: else:
print(f"Error occurred. Here's the info: {e} and text: {post_response.text}")
print(f"PostResponse: {post_response}")
return post_response return post_response
finally:
# PP.pprint(json_get)
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: