d = Dnevnik(login='', password='', group='1979146718386713618')
all_lessons = []
lesson = d.sheludes()
for day_number in range(1, 7): #1 - понедельник
lesson_per_day = lesson[day_number]
if len(lesson_per_day) == 4: # есть одно занятие?
all_lessons.append({
'number': int(lesson[0][0]),
'day': day_number,
'subject': lesson_per_day[0],
'teacher': lesson_per_day[1],
'time': lesson_per_day[2],
'room': lesson_per_day[3],
'type': '' # занятие не над/под чертой
})
elif len(lesson_per_day) == 8: # есть два занятия?
all_lessons.append({
'number': int(lesson[0][0]),
'day': day_number,
'subject': lesson_per_day[0],
'teacher': lesson_per_day[1],
'time': lesson_per_day[2],
'room': lesson_per_day[3],
'type': 'над чертой'
})
all_lessons.append({
'number': int(lesson[0][0]),
'day': day_number,
'subject': lesson_per_day[4],
'teacher': lesson_per_day[5],
'time': lesson_per_day[6],
'room': lesson_per_day[7],
'type': 'под чертой'
})
pprint(all_lessons)
def save_content(response: str, class2: str) -> tuple:
"""Функция парсинга и сохранения таблиц с сайта"""
soup = BeautifulSoup(response, 'lxml')
table = soup.find('table', {'class': class2})
content = []
all_rows = table.findAll('tr')
for row in all_rows:
content.append([])
all_cols = row.findAll('td')
for col in all_cols:
the_strings = [str(s) for s in col.findAll(text=True)]
the_text = ''.join(the_strings)
content[-1].append(the_text)
content = [a for a in content if a != []]
return tuple(content)