This repository has been archived by the owner on Sep 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_timetable.py
126 lines (109 loc) · 4.19 KB
/
generate_timetable.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
import asyncio
import csv
import datetime
import os
import re
from math import floor
import aiofiles
class Class:
def __init__(self, name: str, teacher: str, group: str):
self.name = name
self.teacher = teacher
self.group = group
def levo_desno(data: str) -> (str, str):
w = 30
l = w - len(data)
ll = int(l / 2)
return (" "*ll, " "*ll) if ll == l / 2 else (" "*ll, " "*(ll+1))
async def main():
razred = input("Vpišite razred: ")
start = datetime.date(day=1, month=9, year=2023)
now = datetime.date.today() + datetime.timedelta(weeks=1)
classes = [
[[], [], [], [], [], [], [], [], [], [], []],
[[], [], [], [], [], [], [], [], [], [], []],
[[], [], [], [], [], [], [], [], [], [], []],
[[], [], [], [], [], [], [], [], [], [], []],
[[], [], [], [], [], [], [], [], [], [], []],
]
try:
if len(razred) != 2:
return
class_level = int(razred[0])
base_class = razred[1:].upper()
except Exception as e:
print(f"[TIMETABLE GENERATOR] Could not obtain class level: {e}.")
return
print(f"[TIMETABLE GENERATOR] Found {class_level}. {base_class}.")
try:
regex_match = f"{class_level}[A-HŠ]*\.\.|{class_level}[A-HŠ]*{base_class}[A-HŠ]*"
except:
print(f"[TIMETABLE GENERATOR] Could not find class_level and base_class")
return
while start <= now:
wd = start.weekday()
day = f"{start.day}.{start.month}"
sharepoint_filenames = [
f"substitutions/nadomeščanje_{day}.csv",
f"substitutions/nadomescanje_{day}.csv",
f"substitutions/nadomeščenje_{day}.csv",
f"substitutions/nadomescenje_{day}.csv",
]
for sharepoint_filename in sharepoint_filenames:
if not os.path.exists(sharepoint_filename):
continue
async with aiofiles.open(sharepoint_filename, "r") as f:
ls = await f.readlines()
lines = csv.reader(ls, delimiter=',')
for csv_values in lines:
try:
re.findall(regex_match, csv_values[1])[0]
except Exception as e:
#print(f"[UNTIS 2023/24 v2] No match found for {class_level}. {base_class} and regex {regex_match} with {csv_values[1]}: {e}")
continue
if " - " in csv_values[0]:
h = csv_values[0].split(" - ")
hours = range(int(h[0]), int(h[1]) + 1)
else:
hours = [int(csv_values[0])]
# print(hours)
c = Class(name=csv_values[6], teacher=csv_values[2], group=csv_values[1])
for hour in hours:
found = False
for i in classes[wd][hour]:
if i.teacher == c.teacher:
found = True
break
if found:
continue
classes[wd][hour].append(c)
start += datetime.timedelta(days=1)
for h in range(10):
print(f"{h}. ura")
m = 0
for d in range(5):
m = max(len(classes[d][h]), m)
if m == 0:
continue
#vrstic = m*3+(m-1)
for mv in range(m):
for t in range(2):
for d in range(5):
if len(classes[d][h]) <= mv:
data = ""
else:
if t == 0:
data = f"{classes[d][h][mv].name} ({classes[d][h][mv].group})"
else:
data = classes[d][h][mv].teacher
levo, desno = levo_desno(data)
print(f"|{levo}{data}{desno}", end="")
print("|")
for d in range(5):
if len(classes[d][h]) <= mv:
print("|" + " " * 30, end="")
else:
print("|" + "-" * 30, end="")
print("|")
print("-"*(31*5+1))
asyncio.run(main())