This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues or pull requests.
l9_stud_bot/database/shedule.py

61 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from .l9 import L9_DB
from .a_ssau_parser import *
class Shedule_DB:
"""Класс взаимодействия с базой расписания"""
def __init__(self, l9lk: L9_DB):
self.l9lk = l9lk
self.db = l9lk.db
self.db.executeFile('shedule')
def checkGroupExists(self, groupName: str, l9Id: str) -> str:
"""Проверка наличия группы в БД и на сайте, а также проверка,
что пользователь ещё не подключен к группе
'OK;N_группы;Назв-е_спец-сти' - пользователь успешно подключен \n
'Exists' - пользователь уже подключен к данной группе \n
'ssau.ru/groupId=*' - группа отсутствует в базе, но есть на сайте \n
'Error' - ошибка на стороне сайта
'Empty' - группа нигде не обнаружена
"""
groupIdInDB = self.l9lk.db.get(
'groups',
f'groupName LIKE "%{groupName}%"',
['groupId', 'groupName', 'specName'],
)
if groupIdInDB != []:
groupIdInDB = groupIdInDB[0]
exists = self.l9lk.db.get(
'groups_users',
f'l9Id = {l9Id} AND groupId = {groupIdInDB[0]}',
)
if exists == []:
self.l9lk.db.insert(
'groups_users',
{'l9Id': l9Id, 'groupId': groupIdInDB[0]},
)
return f'OK;{groupIdInDB[1]};{groupIdInDB[2]}'
else:
return 'Exists'
else:
group = findInRasp(groupName)
if group != None:
group_url = f'ssau.ru/{group["url"][2:]}'
gr_num = group["text"]
groupId = group["id"]
return group_url
elif group == 'Error':
return 'Error'
else:
return 'Empty'