Skip to content

Instantly share code, notes, and snippets.

@ahmethakanbesel
Last active February 26, 2023 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmethakanbesel/17d1e4ede03d5e8f11ce8a47fa4d8584 to your computer and use it in GitHub Desktop.
Save ahmethakanbesel/17d1e4ede03d5e8f11ce8a47fa4d8584 to your computer and use it in GitHub Desktop.
from itertools import combinations
num_of_courses = 2 # number of courses except mandatory courses
# [day, hour]
# Monday=1 ... Friday=5
te_courses = [
{'id': 'CSE4057', 'fullName': 'Information Systems Security', 'hours': [[4, 2], [4, 3], [5, 3]]},
{'id': 'CSE4060', 'fullName': 'Principles of Prog. Lang.', 'hours': [[1, 4], [1, 5], [5, 1]]},
{'id': 'CSE4062', 'fullName': 'Introduction to Data Science', 'hours': [[2, 2], [2, 3], [5, 2]]},
{'id': 'CSE4063', 'fullName': 'Fundamentals of Data Mining', 'hours': [[2, 6], [2, 7], [5, 7]]},
{'id': 'CSE4075', 'fullName': 'Wireless & Mobile Networks', 'hours': [[2, 4], [5, 5], [5, 6]]},
{'id': 'CSE4078', 'fullName': 'Introduction to NLP', 'hours': [[1, 2], [1, 3], [2, 5]]},
{'id': 'CSE4093', 'fullName': 'Special Topics I', 'hours': [[3, 6], [3, 7], [4, 4]]},
{'id': 'CSE4095', 'fullName': 'Special Topics III', 'hours': [[2, 1], [4, 6], [4, 7]]},
]
mandatory_courses = [
{'id': 'CSE4079', 'fullName': 'Introduction to Deep Learning', 'hours': [[1, 6], [1, 7], [4, 5]]},
]
timetables = []
for comb in combinations(te_courses, num_of_courses):
timetable = [[[] for j in range(9)] for i in range(6)]
timetable[0] = ["08:30-09:20",
"09:30-10:20",
"10:30-11:20",
"11:30-12:20",
"13:00-13:50",
"14:00-14:50",
"15:00-15:50",
"16:00-16:50",
"17:00-17:50"
]
for course in comb:
for hour in course['hours']:
timetable[hour[0]][hour[1]] = course['fullName']
timetables.append(timetable)
for timetable in timetables:
for course in mandatory_courses:
for hour in course['hours']:
timetable[hour[0]][hour[1]] = course['fullName']
html_tables = []
for timetable in timetables:
lines = []
for hour in range(9):
tr = ''
for day in range(6):
tr += f'<td>{timetable[day][hour]}</td>'
tr = f'<tr>{tr}</tr>'
lines.append(tr)
html_table = f'<table> <tr style="background: cadetblue;"> <th>Hour</th> <th>Monday</th> <th>Tuesday</th> <th>Wednesday</th> <th>Thursday</th> <th>Friday</th> </tr> {"".join(lines)} </table>'
html_tables.append(html_table)
style = "<style>td:nth-child(1) {background:khaki;}</style>"
with open("output.html", "w") as file:
# Write the string to the file
file.write(style + ''.join(html_tables))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment