update putToWord function
This commit is contained in:
1 file changed
+10
-10
+10
-10
@@ -6,23 +6,26 @@ import json
|
||||
|
||||
flex = ("XAT--12A-S", "XAT--12B-S")
|
||||
|
||||
def putScheduleToWord(student):
|
||||
def putMasterTimetable(timetable: dict):
|
||||
pass
|
||||
|
||||
def putScheduleToWord(courses: dict, student: dict, output_dir: str='./output/final/student_schedules') -> None:
|
||||
|
||||
# create an instance of a word doc.
|
||||
doc = docx.Document()
|
||||
|
||||
doc.add_heading(f'Schedule for Student {student["Pupil #"]}')
|
||||
|
||||
# Create a table object
|
||||
table = doc.add_table(rows=1, cols=4)
|
||||
table = doc.add_table(rows=1, cols=3)
|
||||
table.autofit = True
|
||||
table.style = 'Colorful List'
|
||||
|
||||
# course name + (code) | block | semester | room
|
||||
# course name + (code) | block | semester
|
||||
row = table.rows[0].cells
|
||||
row[0].text = 'Course'
|
||||
row[1].text = 'Block'
|
||||
row[2].text = 'Sem.'
|
||||
row[3].text = 'Room #'
|
||||
|
||||
table.columns[0].width = Inches(3.5)
|
||||
table.columns[1].width = Inches(0.75)
|
||||
@@ -34,21 +37,18 @@ def putScheduleToWord(student):
|
||||
else: courseName = courses[courseCode[:-2]]["Description"]
|
||||
blockNum = int(block.split('block')[1])
|
||||
semester = 2 if blockNum > 5 else 1
|
||||
if blockNum > 5: blockNum -= 5
|
||||
if blockNum > (len(student["schedule"])/2): blockNum -= (len(student["schedule"])/2)
|
||||
row = table.add_row().cells
|
||||
row[0].text = f'{courseName}\n({courseCode})'
|
||||
row[1].text = str(blockNum)
|
||||
row[2].text = str(semester)
|
||||
row[3].text = 'B101'
|
||||
|
||||
for row in table.rows:
|
||||
row.height = Inches(0.75)
|
||||
|
||||
doc.save(f'../output/student_schedules/{student["Pupil #"]}_schedule.docx')
|
||||
doc.save(f'{output_dir}/{student["Pupil #"]}_schedule.docx')
|
||||
|
||||
def main():
|
||||
global courses
|
||||
|
||||
# Get students
|
||||
try:
|
||||
with open("../output/students.json", 'r') as studentFile: students = json.load(studentFile)
|
||||
@@ -63,7 +63,7 @@ def main():
|
||||
|
||||
# Define students grade level
|
||||
for student in students:
|
||||
putScheduleToWord(student)
|
||||
putScheduleToWord(courses, student, '../output/final/student_schedules')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user