|
| 1 | +import csv |
| 2 | +import asyncio |
| 3 | +import aiohttp |
| 4 | +import ssl |
| 5 | + |
| 6 | +ssl_context = ssl.create_default_context() |
| 7 | +ssl_context.check_hostname = False |
| 8 | +ssl_context.verify_mode = ssl.CERT_NONE |
| 9 | + |
| 10 | +with open('./data/attendance-task/results.csv', newline='') as csvfile: |
| 11 | + reader = csv.reader(csvfile) |
| 12 | + counter = 0 |
| 13 | + total_coutner = 0 |
| 14 | + memo = {} |
| 15 | + for row in reader: |
| 16 | + if total_coutner == 0: |
| 17 | + total_coutner += 1 |
| 18 | + continue |
| 19 | + |
| 20 | + sessionId = row[0] |
| 21 | + if sessionId == "a0pcX0000005lZNQAY": |
| 22 | + continue |
| 23 | + coach1 = row[4] |
| 24 | + coach2 = row[5] |
| 25 | + attendanceDate = row[6] |
| 26 | + memo[sessionId] = (coach1, coach2, attendanceDate) |
| 27 | + |
| 28 | + total_coutner += 1 |
| 29 | + |
| 30 | + |
| 31 | + # reader = csv.reader(csvfile) |
| 32 | + # print(f"Total coach mismatches: {counter}") |
| 33 | + # print(f"Total records: {total_coutner}") |
| 34 | + async def send_post_request(http_session, session, coach, endOfTeamSeason): |
| 35 | + url = "https://localhost:8091/api/tasks" |
| 36 | + headers = { |
| 37 | + 'Content-Type': 'application/json' |
| 38 | + } |
| 39 | + payload = { |
| 40 | + "AssignedBy": "", |
| 41 | + "AssignedTo": coach, |
| 42 | + "CreatedByContact": "0051T000009eHfvQAE", |
| 43 | + "CreatedContact": "", |
| 44 | + "LastModifiedBy": "0051T000009eHfvQAE", |
| 45 | + "LastModifiedContact": "", |
| 46 | + "OwnerId": "0051T000009eHfvQAE", |
| 47 | + "DueDate": endOfTeamSeason, |
| 48 | + "Session": session, |
| 49 | + "Name": "Catch-up attendance", |
| 50 | + "TaskStatus": "To Do", |
| 51 | + "TaskType": "Take Attendance" |
| 52 | + } |
| 53 | + |
| 54 | + try: |
| 55 | + async with http_session.post(url, headers=headers, json=payload, ssl=ssl_context) as response: |
| 56 | + return await response.text(), response.status |
| 57 | + except Exception as e: |
| 58 | + print(e) |
| 59 | + return None, None |
| 60 | + |
| 61 | + async def main(): |
| 62 | + async with aiohttp.ClientSession() as http_session: |
| 63 | + for session_id, (coach1, coach2, end_of_team_season) in memo.items(): |
| 64 | + print(f"Processing session {session_id} with coaches {coach1} and {coach2} ({end_of_team_season})") |
| 65 | + if coach1 == coach2: |
| 66 | + resp = await send_post_request(http_session, session_id, coach1, end_of_team_season) |
| 67 | + print(resp) |
| 68 | + else: |
| 69 | + resp1 = await send_post_request(http_session, session_id, coach1, end_of_team_season) |
| 70 | + print(resp1) |
| 71 | + resp2 = await send_post_request(http_session, session_id, coach2, end_of_team_season) |
| 72 | + print(resp2) |
| 73 | + print(f"------------------------------------------------------------------------------------------") |
| 74 | + |
| 75 | + asyncio.run(main()) |
0 commit comments