-
Notifications
You must be signed in to change notification settings - Fork 0
/
AttendanceFunction.py
79 lines (62 loc) · 2.79 KB
/
AttendanceFunction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from EncryptAndDecryptFunction import *
from HttpRequestFunction import *
import requests
import json
fileName = "demoConfig.json"
def retrieveSesId():
# Load the runId saved
tempFile = open(fileName)
jsonTempFile = json.load(tempFile)
runId = jsonTempFile["runId"]
uen = jsonTempFile["UEN"]
courseReferenceNumber = jsonTempFile["CourseRefNum"]
#print(runId, uen, courseReferenceNumber)
# Call a Get HTTP to see if runId exists
print("Search up for Session ID")
resp = getHttpRequest("https://uat-api.ssg-wsg.sg/courses/runs/" + str(runId) + "/sessions" + "?uen="+ str(uen) + "&courseReferenceNumber=" + str(courseReferenceNumber))
print(resp.text)
return resp
def saveSesIdDetails(resp):
configInfo = loadFile(fileName)
configInfo = json.loads(configInfo)
configInfo["SesId"] = resp.json()["data"]["sessions"][0]["id"]
saveJsonFormat(configInfo, fileName)
def retrieveAttendance():
tempFile = open(fileName)
jsonTempFile = json.load(tempFile)
runId = jsonTempFile["runId"]
uen = jsonTempFile["UEN"]
courseReferenceNumber = jsonTempFile["CourseRefNum"]
sesId = jsonTempFile["SesId"]
baseRetrieveAttendanceurl = "https://uat-api.ssg-wsg.sg/courses/runs/"
response = getHttpRequest(baseRetrieveAttendanceurl + str(runId) + "/sessions/attendance?uen=" + str(uen) + "&courseReferenceNumber=" + str(courseReferenceNumber) + "&sessionId=" + str(sesId))
result = doDecryption(response.text)
pprintJsonFormat(result)
def uploadAttendance():
saveSesIdDetails(retrieveSesId())
updateAttendancePayload()
tempFile = open(fileName)
jsonTempFile = json.load(tempFile)
runId = jsonTempFile["runId"]
baseAttendanceURL = "https://uat-api.ssg-wsg.sg/courses/runs/" + str(runId) + "/sessions/attendance"
attendancePayload = loadFile("AttendancePayLoad.json")
ciptertext = doEncryption(attendancePayload.encode())
response = postHttpRequestJson(baseAttendanceURL, ciptertext.decode())
print(response.text)
if (response.status_code < 400):
print("Successfully uploaded Attendance")
else:
raise Exception
#Update the latest Session Id, UEN ,and Course Ref Number payload according to the config file
def updateAttendancePayload():
#load config File
configInfo = loadFile(fileName)
configInfoJson = json.loads(configInfo)
#load Attendance Json File
attendancePayload = loadFile("AttendancePayLoad.json")
attendancePayload = json.loads(attendancePayload)
#Update the latest value and save
attendancePayload["course"]["sessionID"] = configInfoJson["SesId"]
attendancePayload["course"]["referenceNumber"] = configInfoJson["CourseRefNum"]
attendancePayload["uen"] = configInfoJson["UEN"]
saveJsonFormat(attendancePayload, "AttendancePayLoad.json")