-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
423 lines (334 loc) · 18 KB
/
main.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#Import course Run py Functions
from AssessmentFunction import addAssessment
from EnrolmentFunction import addEnrolment, enrollmentInitialization
from AttendanceFunction import uploadAttendance
from courseRunFunctions import *
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import simpledialog
from tkinter import messagebox
import json
import datetime
from PIL import ImageTk, Image
from tkinter import filedialog
import pandas as pd
import pyjsonviewer
# Open the json file where the "courserun info" is being stored
with open("CourseRunPayLoad.json") as f:
# Load the json file data into local variable "data"
data = json.load(f)
# Store the list of data into local variable "courseTPinfo & courseRuninfo"
courseTPinfo = data["course"]
courseRuninfo = data["course"]["runs"]
courseTPUEN = courseTPinfo["trainingProvider"]["uen"]
courseRefNumber = courseTPinfo["courseReferenceNumber"]
courseAdminEmail = courseRuninfo[0]["courseAdminEmail"]
def load_json_config():
# Open the json file where the "config info" is being stored
with open("config.json") as f:
# Load the json file data into local variable "data"
data = json.load(f)
return data
def load_json_demoConfig():
# Open the json file where the "config info" is being stored
with open("demoConfig.json") as f:
# Load the json file data into local variable "data"
data = json.load(f)
return data
# Open the json file where the "enrolment info" is being stored
with open("EnrolmentPayLoad.json") as f:
# Load the json file data into local variable "data"
data2 = json.load(f)
# Store the list of data into local variable enrolmentinfo"
courseEnrolmentInfo = data2["enrolment"]
enrolmentCourseId = courseEnrolmentInfo["course"]["run"]["id"]
enrolmentRefNo = courseEnrolmentInfo["course"]["referenceNumber"]
enrolmentTpUen = courseEnrolmentInfo["trainingPartner"]["uen"]
# Open the json file where the "attendance info" is being stored
with open("AttendancePayLoad.json") as f:
# Load the json file data into local variable "data"
attendanceData = json.load(f)
# Store the list of data into local variable enrolmentinfo"
attendanceSessionId = attendanceData["course"]["sessionID"]
attendanceRefNo = attendanceData["course"]["referenceNumber"]
attendanceTpUen = attendanceData["uen"]
# Open the json file where the "Assessment info" is being stored
with open("AssessmentPayLoad.json") as f:
# Load the json file data into local variable "data"
assessmentData = json.load(f)
# Store the list of data into local variable enrolmentinfo"
assessmentRunId = assessmentData["assessment"]["course"]["run"]["id"]
assessmentRefNo = assessmentData["assessment"]["course"]["referenceNumber"]
assessmentTpUen = assessmentData["assessment"]["trainingPartner"]["uen"]
# Quit Program
def quit_program():
quit()
class APIProject(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, *kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne, PageTwo, PageThree, PageFour, FinalPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
# Starting Page (Press to start the Navigation/ Exit)
# 2 options for the user to choose from
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
load = Image.open("SKFMenuPage.JPG")
render = ImageTk.PhotoImage(load)
# labels can be text or images
img2 = Label(self, image=render)
img2.image = render
img2.place(x=0, y=0, relwidth=1, relheight=1)
button1 = tk.Button(self, text="Press to start the Navigation", bg="white", width=25, pady=5,
command=lambda: controller.show_frame(PageOne)) # go to Page One
button1.place(relx=0.5, rely=0.65, anchor=CENTER)
button2 = tk.Button(self, text="Exit", bg="white", width=25, pady=5,
command=quit_program) # quit program
button2.place(relx=0.5, rely=0.7, anchor=CENTER)
# Add course run into API
class PageOne(tk.Frame):
def __init__(self, parent, controller):
#load initialization method from courseRunFunctions.py
courseRunInitialization()
tk.Frame.__init__(self, parent)
self.inner = tk.Frame(self)
self.inner.place(relx=0.5, rely=0.2, anchor=CENTER)
load = Image.open("SKFCoursePage.JPG")
render = ImageTk.PhotoImage(load)
# labels can be text or images
img2 = Label(self, image=render)
img2.image = render
img2.place(x=0, y=0, relwidth=1, relheight=1)
label1 = tk.Label(self, text="You are about to add a Course Run to the course below: ")
label1.place(relx=0.5, rely=0.15, anchor=CENTER)
label2 = tk.Label(self, text="Course Reference Number: " + courseRefNumber)
label2.place(relx=0.5, rely=0.2, anchor=CENTER)
label3 = tk.Label(self, text="Training Provider UEN: " + courseTPUEN)
label3.place(relx=0.5, rely=0.25, anchor=CENTER)
label4 = tk.Label(self, text="Course Admin Email: " + courseAdminEmail)
label4.place(relx=0.5, rely=0.3, anchor=CENTER)
def AddCourse():
try:
addCourserun()
data = load_json_config()
messagebox.showinfo("Successful", "Status Code: 200 \nAdded Course into API. The Course Run ID is " + str(data["runId"]))
print(str(data["runId"]))
except:
data = load_json_config()
messagebox.showerror("Invalid Response", "Status Code: 400 \nCourse Run already exist. The Course Run ID is " + str(data["runId"]), )
print(str(data["runId"]))
def DownloadFile():
try:
df = pd.read_json('C:/Users/User/Desktop/application/APIApplication/CourseRunPayLoad.json')
df.to_csv(filedialog.asksaveasfilename(defaultextension='.csv'))
messagebox.showinfo("Successful", "CSV file has been downloaded")
except:
print("user didnt save.")
def ViewCourseRunJsonFile():
pyjsonviewer.view_data(json_file="C:/Users/User/Desktop/application/APIApplication/CourseRunPayLoad.json")
# When button is pressed, function should be called
AddButton = tk.Button(self, command=AddCourse, text='Add', width=10, pady=5, bg="white")
AddButton.place(relx=0.5, rely=0.5, anchor=CENTER)
BackButton = tk.Button(self, text="Back", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(StartPage))
BackButton.place(relx=0.3, rely=0.5, anchor=CENTER)
NextButton = tk.Button(self, text="Next", width=10, pady=5, bg="white", command=lambda: controller.show_frame(PageTwo))
NextButton.place(relx=0.7, rely=0.5, anchor=CENTER)
ViewButton = tk.Button(self, text="Download course run in CSV", width=22, pady=5, bg="white",
command=DownloadFile)
ViewButton.place(relx=0.5, rely=0.6, anchor=CENTER)
ViewCourseRunJsonButton = tk.Button(self, text="View course run in json", width=18, pady=5, bg="white",
command=ViewCourseRunJsonFile)
ViewCourseRunJsonButton.place(relx=0.5, rely=0.65, anchor=CENTER)
# Add enrollment into API
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.inner = tk.Frame(self)
self.inner.place(relx=0.5, rely=0.2, anchor=CENTER)
load = Image.open("SKFEnrolmentPage.JPG")
render = ImageTk.PhotoImage(load)
# labels can be text or images
img2 = Label(self, image=render)
img2.image = render
img2.place(x=0, y=0, relwidth=1, relheight=1)
label1 = tk.Label(self, text="You are about to add an Enrolment")
label1.place(relx=0.5, rely=0.15, anchor=CENTER)
label2 = tk.Label(self, text="Enrolment Course Run ID: " + str(enrolmentCourseId))
label2.place(relx=0.5, rely=0.2, anchor=CENTER)
label3 = tk.Label(self, text="Enrolment Reference No: " + enrolmentRefNo)
label3.place(relx=0.5, rely=0.25, anchor=CENTER)
label4 = tk.Label(self, text="Enrolment TP UEN: " + enrolmentTpUen)
label4.place(relx=0.5, rely=0.3, anchor=CENTER)
def AddEnrollment():
try:
addEnrolment()
data = load_json_demoConfig()
messagebox.showinfo("Successful", "Status Code: 200 \nAdded Enrolment into API Your Enrolment ID is " +
(data["enrollRefNum"]))
print((data["enrollRefNum"]))
except:
data = load_json_demoConfig()
messagebox.showerror("Invalid Response",
"Status Code: 400 \nEnrolmentID already exist. The Enrolment ID is " +
(data["enrollRefNum"]))
print((data["enrollRefNum"]))
def DownloadFile():
try:
df = pd.read_json('C:/Users/User/Desktop/application/APIApplication/EnrolmentPayload.json')
df.to_csv(filedialog.asksaveasfilename(defaultextension='.csv'))
messagebox.showinfo("Successful", "CSV file has been downloaded")
except:
print("user didnt save.")
def ViewEnrolmentJsonFile():
pyjsonviewer.view_data(json_file="C:/Users/User/Desktop/application/APIApplication/EnrolmentPayload.json")
# When button is pressed, function should be called
AddButton = tk.Button(self, command=AddEnrollment, text='Add', width=10, pady=5, bg="white")
AddButton.place(relx=0.5, rely=0.5, anchor=CENTER)
BackButton = tk.Button(self, text="Back", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(StartPage))
BackButton.place(relx=0.3, rely=0.5, anchor=CENTER)
NextButton = tk.Button(self, text="Next", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(PageThree))
NextButton.place(relx=0.7, rely=0.5, anchor=CENTER)
ViewButton = tk.Button(self, text="Download Enrolment in CSV", width=22, pady=5, bg="white",
command=DownloadFile)
ViewButton.place(relx=0.5, rely=0.6, anchor=CENTER)
ViewEnrolmentJsonButton = tk.Button(self, text="View Enrolment in json", width=18, pady=5, bg="white",
command=ViewEnrolmentJsonFile)
ViewEnrolmentJsonButton.place(relx=0.5, rely=0.65, anchor=CENTER)
# Add attendance into API
class PageThree(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.inner = tk.Frame(self)
self.inner.place(relx=0.5, rely=0.2, anchor=CENTER)
load = Image.open("SKFAttendancePage.JPG")
render = ImageTk.PhotoImage(load)
# labels can be text or images
img2 = Label(self, image=render)
img2.image = render
img2.place(x=0, y=0, relwidth=1, relheight=1)
label1 = tk.Label(self, text="You are about to add an Attendance")
label1.place(relx=0.5, rely=0.15, anchor=CENTER)
label2 = tk.Label(self, text="Attendance Course Session ID: " + attendanceSessionId)
label2.place(relx=0.5, rely=0.2, anchor=CENTER)
label3 = tk.Label(self, text="Attendance Course Reference No: " + attendanceRefNo)
label3.place(relx=0.5, rely=0.25, anchor=CENTER)
label4 = tk.Label(self, text="Attendance TP UEN: " + attendanceTpUen)
label4.place(relx=0.5, rely=0.3, anchor=CENTER)
def AddAttendance():
try:
uploadAttendance()
messagebox.showinfo("Successful", "Status Code: 200 \nAdded Attendance into API")
except:
messagebox.showerror("Invalid Response",
"Status Code: 400 \nAttendance already taken.")
def DownloadFile():
try:
df = pd.read_json('C:/Users/User/Desktop/application/APIApplication/AttendancePayload.json')
df.to_csv(filedialog.asksaveasfilename(defaultextension='.csv'))
messagebox.showinfo("Successful", "CSV file has been downloaded")
except:
print("user didnt save.")
def ViewAttendanceJsonFile():
pyjsonviewer.view_data(json_file="C:/Users/User/Desktop/application/APIApplication/AttendancePayload.json")
# When button is pressed, function should be called
AddButton = tk.Button(self, command=AddAttendance, text='Add', width=10, pady=5, bg="white")
AddButton.place(relx=0.5, rely=0.5, anchor=CENTER)
BackButton = tk.Button(self, text="Back", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(StartPage))
BackButton.place(relx=0.3, rely=0.5, anchor=CENTER)
NextButton = tk.Button(self, text="Next", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(PageFour))
NextButton.place(relx=0.7, rely=0.5, anchor=CENTER)
ViewButton = tk.Button(self, text="Download Attendance in CSV", width=22, pady=5, bg="white",
command=DownloadFile)
ViewButton.place(relx=0.5, rely=0.6, anchor=CENTER)
ViewAttendanceJsonButton = tk.Button(self, text="View Attendance in json", width=18, pady=5, bg="white",
command=ViewAttendanceJsonFile)
ViewAttendanceJsonButton.place(relx=0.5, rely=0.65, anchor=CENTER)
# Add assessment into API
class PageFour(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.inner = tk.Frame(self)
self.inner.place(relx=0.5, rely=0.2, anchor=CENTER)
load = Image.open("SKFAssessmentPage.JPG")
render = ImageTk.PhotoImage(load)
# labels can be text or images
img2 = Label(self, image=render)
img2.image = render
img2.place(x=0, y=0, relwidth=1, relheight=1)
label1 = tk.Label(self, text="You are about to add an Assessment")
label1.place(relx=0.5, rely=0.15, anchor=CENTER)
label2 = tk.Label(self, text="Assessment Course Run ID: " + assessmentRunId)
label2.place(relx=0.5, rely=0.2, anchor=CENTER)
label3 = tk.Label(self, text="Assessment Course Reference No: " + assessmentRefNo)
label3.place(relx=0.5, rely=0.25, anchor=CENTER)
label4 = tk.Label(self, text="Assessment TP UEN: " + assessmentTpUen)
label4.place(relx=0.5, rely=0.3, anchor=CENTER)
def AddAssessment():
try:
addAssessment()
data = load_json_demoConfig()
messagebox.showinfo("Successful", "Status Code: 200 \nAdded Assessment into API Your Assessment Reference Number is ")
(data["AssessmentRefNum"])
except:
data = load_json_demoConfig()
messagebox.showerror("Invalid Response",
"Status Code: 400 \nAssessment already exist.")
def DownloadFile():
try:
df = pd.read_json('C:/Users/User/Desktop/application/APIApplication/AssessmentPayload.json')
df.to_csv(filedialog.asksaveasfilename(defaultextension='.csv'))
messagebox.showinfo("Successful", "CSV file has been downloaded")
except:
print("user didnt save.")
def ViewAssessmentJsonFile():
pyjsonviewer.view_data(json_file="C:/Users/User/Desktop/application/APIApplication/AssessmentPayload.json")
# When button is pressed, function should be called
AddButton = tk.Button(self, command=AddAssessment, text='Add', width=10, pady=5, bg="white")
AddButton.place(relx=0.5, rely=0.5, anchor=CENTER)
BackButton = tk.Button(self, text="Back", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(StartPage))
BackButton.place(relx=0.3, rely=0.5, anchor=CENTER)
NextButton = tk.Button(self, text="Next", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(FinalPage))
NextButton.place(relx=0.7, rely=0.5, anchor=CENTER)
ViewButton = tk.Button(self, text="Download Assessment in CSV", width=22, pady=5, bg="white",
command=DownloadFile)
ViewButton.place(relx=0.5, rely=0.6, anchor=CENTER)
ViewAssessmentJsonButton = tk.Button(self, text="View Assessment in json", width=18, pady=5, bg="white",
command=ViewAssessmentJsonFile)
ViewAssessmentJsonButton.place(relx=0.5, rely=0.65, anchor=CENTER)
class FinalPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
load = Image.open("SKFFinalPage.JPG")
render = ImageTk.PhotoImage(load)
# labels can be text or images
img2 = Label(self, image=render)
img2.image = render
img2.place(x=0, y=0, relwidth=1, relheight=1)
BackButton = tk.Button(self, text="Back", width=10, pady=5, bg="white",
command=lambda: controller.show_frame(StartPage))
BackButton.place(relx=0.5, rely=0.55, anchor=CENTER)
button1 = tk.Button(self, text="Press to Exit App", bg="white", width=20, pady=5,
command=quit_program) # quit program
button1.place(relx=0.5, rely=0.6, anchor=CENTER)
app = APIProject()
app.geometry("500x747")
app.mainloop()