-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroups.py
64 lines (48 loc) · 1.98 KB
/
groups.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
import pandas as pd
import re
from convert import pdf_to_excel, download_pdf
download_pdf('http://www.krstc.ru/files/raspis/s1', 'files/testpd.pdf')
pdf_to_excel('files/testpd.pdf', 'files/testxl.xlsx')
df = pd.read_excel("files/testxl.xlsx", sheet_name="Sheet1", header=None)
def get_student_groups(df):
number = 3
student_groups = {}
first_row = df.iloc[0]
for line in first_row:
if re.search(r'\d{2}К$', str(line)):
line = line.upper()
student_groups[line] = number
number += 2
return student_groups
student_groups = get_student_groups(df)
def get_schedule(df, student_group, today_day):
offset = 11
week = {'пн': offset*0, 'вт': offset*1, 'ср': offset*2, 'чт': offset*3, 'пт': offset*4}
format_week = {'пн': 'понедельник', 'вт': 'вторник', 'ср': 'среда', 'чт': 'четверг', 'пт': 'пятница'}
j = student_groups[student_group]
i = 3 # начальное значение индекса
data = []
corp = df[j][i+week[today_day]-1]
while i < (len(df)+2):
key = df[2][i+week[today_day]]
value = df[j][i+week[today_day]]
cab = df[j+1][i+week[today_day]]
day = today_day
group = student_group
key = '' if pd.isna(key) else key
value = '' if pd.isna(value) else value
cab = '' if pd.isna(cab) else cab
if (not key or not value or not cab) and data:
break
if isinstance(key, str):
key = re.sub(r'-(\s*)\n', '-', key)
if isinstance(value, str):
value = value.replace('\n', ' ')
if isinstance(cab, str):
cab = cab.replace('\n', ' ')
if key and value and cab:
data.append([key, value, cab])
i += 1
result = "\n".join(f"🎓{row[0]}: {row[1]}: каб. {row[2]}" for row in data)
result = f' {group}\n{format_week[day]}\n{corp}\n\n{result}'
return result