-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInterface.py
More file actions
87 lines (69 loc) · 2.85 KB
/
Copy pathUserInterface.py
File metadata and controls
87 lines (69 loc) · 2.85 KB
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
# -*- coding: utf-8 -*-
import sqlite3
from Settings import *
from html2image import Html2Image
def to_standard(text):
return text[0].upper() + text[1:]
def get_data(group):
conn = sqlite3.connect(db_path)
cur = conn.cursor()
cur.execute(f"{group_sql_request}'{group}'")
one_result = cur.fetchone()
if (one_result == None):
print(f"Группа с таким названием как {group} не найдена")
conn.commit()
return
gid = one_result[0]
cur.execute(data_sql_request + str(gid))
data = cur.fetchall()
timetable = [[[[] for j in range(0, 9)] for i in range(0, 6)] for k in range(0, 2)]
for record in data:
timetable[record[0]][record[1]][record[2]].append([record[3], to_standard(record[4]), record[5], record[6],
record[7]])
conn.commit()
return timetable
def create_HTML(timetable, group):
global global_timetable
html = f"{html_header}<H1>Расписание для группы {group}</H1>\n<H2>Чётная неделя</H2>\n"
html += template + create_table(timetable[0]) + "</tbody>\n</table>\n"
html += "<H2>Нечётная неделя</H2>\n" + template + create_table(timetable[1])
global_timetable = timetable
return html
def create_table(timetable):
html = ""
for day in range(0, 6):
html += f"<tr>\n<td><P ALIGN=\"CENTER\">{days[day]}</td>\n"
for par in range(0, 8):
color = "white"
text = "-"
if len(timetable[day][par]) != 0:
text = ""
for record in timetable[day][par]:
if record[3] == 2:
color = "cyan"
elif record[3] == 1:
color = "brown"
text += "-<br>"
continue
text += f"{types[record[0]]}<br>{record[1]}<br>{record[2]}<br>{record[4]}<br>"
html += f"<td style=\"background-color: {color};\"><P ALIGN=\"CENTER\">{text}</p></td>\n"
html += "</tr>\n"
return html
def save_resout(text):
with open(res_html_path, 'w') as f:
f.write(text)
def create_jpg_version(timetable, group):
hti = Html2Image()
for i in range(2):
info = "<H1>Чётная неделя</H1>\n"
if i!=0 :
info = "<H1>Нечётная неделя</H1>\n"
html =html_header+info+template + create_table(timetable[i]) +"</tbody>\n</table>\n</HTML>\n</BODY>\n"
hti.screenshot(html_str=html, save_as=f"Resouts/{i+1}.jpg", size=(1200, 1000))
def create_html_version(timetable, group):
save_resout(create_HTML(timetable, group))
if __name__ == '__main__':
group = "ПИбд-23"
timetable = get_data(group)
create_html_version(timetable, group)
create_jpg_version(timetable, group)