diff --git a/Scripts/Migration_tool/Luma_mass_completions/data.csv b/Scripts/Migration_tool/Luma_mass_completions/data.csv index 2b91f3fd..aa56ce04 100644 --- a/Scripts/Migration_tool/Luma_mass_completions/data.csv +++ b/Scripts/Migration_tool/Luma_mass_completions/data.csv @@ -1,16 +1,3 @@ Completion Date,Email Address,Course Name 2024-04-19,norm@rsmsn.co,This is War -2024-04-20,norm+climbing@northpass.com,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 +2024-04-20,norm@rsmsn.co,This is War diff --git a/Scripts/Migration_tool/Luma_mass_completions/manage_csv_multi.py b/Scripts/Migration_tool/Luma_mass_completions/manage_csv_multi.py new file mode 100644 index 00000000..1e479eea --- /dev/null +++ b/Scripts/Migration_tool/Luma_mass_completions/manage_csv_multi.py @@ -0,0 +1,6 @@ +import pandas as pd + +def import_as_dataframe(): + importfile = "./data.csv" + df = pd.read_csv(importfile) + return df diff --git a/Scripts/Migration_tool/Luma_mass_completions/mark_course_as_complete.py b/Scripts/Migration_tool/Luma_mass_completions/mark_course_as_complete.py index 147260d6..f3833afc 100644 --- a/Scripts/Migration_tool/Luma_mass_completions/mark_course_as_complete.py +++ b/Scripts/Migration_tool/Luma_mass_completions/mark_course_as_complete.py @@ -12,6 +12,7 @@ from utils import calls import manage_csv from datetime import datetime, timedelta import uuid +import json baseurl = calls.BASEURL @@ -40,12 +41,14 @@ project_name = argv[1] def get_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 row_iterator: + # row_iterator = df.iterrows() + # _, last = next(row_iterator) + for i, row in df.iterrows(): email = row["email address"] + print(email) course = row["course name"] date = row["completion date"] + print(date) people_tuple = get_people(email) if people_tuple is None: pass @@ -135,11 +138,11 @@ def create_enrollment_payload(course_uuid, learner_uuid, date_str): "type": "enrollment_resource", "attributes": { "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": { "enrolled_at": formatted_date, "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" print(attempt_url) print(f"Attempt Payload is: {attempt_payload}") + # attempt_payload2 = json.dumps(attempt_payload) attempt_call = calls.post(attempt_url, attempt_payload) print( f"In trying the attempt resource, the following code was returned: {attempt_call.status_code}" diff --git a/Scripts/Migration_tool/Luma_mass_completions/payload.json b/Scripts/Migration_tool/Luma_mass_completions/payload.json new file mode 100644 index 00000000..c7426344 --- /dev/null +++ b/Scripts/Migration_tool/Luma_mass_completions/payload.json @@ -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'}}}]} \ No newline at end of file diff --git a/Scripts/Migration_tool/Luma_mass_completions/utils/__pycache__/calls.cpython-310.pyc b/Scripts/Migration_tool/Luma_mass_completions/utils/__pycache__/calls.cpython-310.pyc index 11e7813c..e1aa738d 100644 Binary files a/Scripts/Migration_tool/Luma_mass_completions/utils/__pycache__/calls.cpython-310.pyc and b/Scripts/Migration_tool/Luma_mass_completions/utils/__pycache__/calls.cpython-310.pyc differ diff --git a/Scripts/Migration_tool/Luma_mass_completions/utils/calls.py b/Scripts/Migration_tool/Luma_mass_completions/utils/calls.py index 4b7b2d1c..d814bb87 100644 --- a/Scripts/Migration_tool/Luma_mass_completions/utils/calls.py +++ b/Scripts/Migration_tool/Luma_mass_completions/utils/calls.py @@ -25,31 +25,21 @@ def get(url): def post(url, payload): - try: - post_response = requests.post(url, headers=HEADERS, json=payload) - print(f"Executed Post Request. Status code is {post_response.status_code}") - except Exception as h: - print( - f"Error occurred. Here's the info: {h} and text: {post_response.text}" - ) - finally: - try: - json_post = post_response.json() - # print(f"JSONResponse: {json_post}") + request_subject = url.split("/")[-2:] + post_response = requests.post(url, headers=HEADERS, json=payload) + print(f"Executed Post Request for {str(request_subject)}.") + if str(post_response.status_code).startswith('2'): + print(f"Status code is {post_response.status_code}") + return post_response.json() + else: + print(f"Status code is {post_response.status_code}") + json_post = post_response.json() + if json_post: + print(json_post) return json_post - except JSONDecodeError as e: - print(f"Error occurred. Here's the info: {e} and text: {post_response.text}") - print(f"PostResponse: {post_response}") + else: 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): try: