import sqlite3 class editPredmet: def __init__(self, database): """Подключаемся к БД и сохраняем курсор соединения""" self.connection = sqlite3.connect(database) self.cursor = self.connection.cursor() def check_predm(self, user_id): """Выбраные предметы""" with self.connection: math = '' rus = '' fiz = '' inf = '' inostr = '' obsh = '' biol = '' temp_russian = self.cursor.execute('SELECT `russia` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() russian = temp_russian[0] math_temp1 = self.cursor.execute('SELECT `math` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp1 = math_temp1[0] rus_temp2 = self.cursor.execute('SELECT `rus` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp2 = rus_temp2[0] fiz_temp3 = self.cursor.execute('SELECT `fiz` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp3 = fiz_temp3[0] inf_temp4 = self.cursor.execute('SELECT `inf` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp4 = inf_temp4[0] inostr_temp5 = self.cursor.execute('SELECT `inostr` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp5 = inostr_temp5[0] obsh_temp6 = self.cursor.execute('SELECT `obsh` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp6 = obsh_temp6[0] biol_temp7 = self.cursor.execute('SELECT `biol` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp7 = biol_temp7[0] if temp1[0] == 1: math = '\n✅ математика' if temp2[0] == 1: rus = '\n✅ русский язык' if temp3[0] == 1: fiz = '\n✅ физика' if temp4[0] == 1: inf = '\n✅ информатика и ИКТ' if temp5[0] == 1: inostr = '\n✅ иностранный язык' if temp6[0] == 1: obsh = '\n✅ обществознание' if temp7[0] == 1: biol = '\n✅ биология' how_bak = 0 how_spec = 0 if (russian[0] == 0): if (temp1[0] == 1 and temp2[0] == 1 and temp4[0] == 1): how_bak += 6 how_spec += 2 if (temp1[0] == 1 and temp2[0] == 1 and temp3[0] == 1): how_bak += 15 how_spec += 7 if (temp1[0] == 1 and temp2[0] == 1 and temp7[0] == 1): how_bak += 0 how_spec += 1 if (temp2[0] == 1 and temp5[0] == 1 and temp6[0] == 1): how_bak += 4 how_spec += 1 if (temp1[0] == 1 and temp2[0] == 1 and temp5[0] == 1): how_bak += 1 how_spec += 0 return (f'По выбраным предметам найдено:\nБакалавриат: {how_bak}\nСпециалитет: {how_spec}\n\nВыбранные Вами предметы:{math}{rus}{fiz}{inf}{inostr}{obsh}{biol}') elif (russian[0] == 1): if (temp1[0] == 1 and temp2[0] == 1 and temp4[0] == 1): how_bak += 3 if (temp1[0] == 1 and temp2[0] == 1 and temp3[0] == 1): how_bak += 5 if (temp2[0] == 1 and temp5[0] == 1 and temp6[0] == 1): how_bak += 3 if (temp1[0] == 1 and temp2[0] == 1 and temp5[0] == 1): how_bak += 1 return (f'По выбраным предметам найдено:\nБакалавриат: {how_bak}\n\nВыбранные Вами предметы:{math}{rus}{fiz}{inf}{inostr}{obsh}{biol}') else: return (f'error 9') def update_all(self, user_id): """Обновляем статус математики""" with self.connection: self.cursor.execute("UPDATE `allusers` SET `math` = 0 WHERE `user_id` = ?", (user_id,)) self.cursor.execute("UPDATE `allusers` SET `rus` = 0 WHERE `user_id` = ?", (user_id,)) self.cursor.execute("UPDATE `allusers` SET `fiz` = 0 WHERE `user_id` = ?", (user_id,)) self.cursor.execute("UPDATE `allusers` SET `inf` = 0 WHERE `user_id` = ?", (user_id,)) self.cursor.execute("UPDATE `allusers` SET `inostr` = 0 WHERE `user_id` = ?", (user_id,)) self.cursor.execute("UPDATE `allusers` SET `obsh` = 0 WHERE `user_id` = ?", (user_id,)) self.cursor.execute("UPDATE `allusers` SET `biol` = 0 WHERE `user_id` = ?", (user_id,)) return 0 def update_math(self, user_id): """Обновляем статус математики""" with self.connection: math_temp = self.cursor.execute('SELECT `math` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = math_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `math` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `math` = 0 WHERE `user_id` = ?", (user_id,)) def update_rus(self, user_id): """Обновляем статус русского языка""" with self.connection: rus_temp = self.cursor.execute('SELECT `rus` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = rus_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `rus` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `rus` = 0 WHERE `user_id` = ?", (user_id,)) def update_fiz(self, user_id): """Обновляем статус физики""" with self.connection: fiz_temp = self.cursor.execute('SELECT `fiz` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = fiz_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `fiz` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `fiz` = 0 WHERE `user_id` = ?", (user_id,)) def update_inf(self, user_id): """Обновляем статус информатики""" with self.connection: inf_temp = self.cursor.execute('SELECT `inf` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = inf_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `inf` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `inf` = 0 WHERE `user_id` = ?", (user_id,)) def update_inostr(self, user_id): """Обновляем статус иностраного""" with self.connection: inostr_temp = self.cursor.execute('SELECT `inostr` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = inostr_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `inostr` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `inostr` = 0 WHERE `user_id` = ?", (user_id,)) def update_obsh(self, user_id): """Обновляем статус обществознания""" with self.connection: obsh_temp = self.cursor.execute('SELECT `obsh` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = obsh_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `obsh` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `obsh` = 0 WHERE `user_id` = ?", (user_id,)) def update_biol(self, user_id): """Обновляем статус биологии""" with self.connection: biol_temp = self.cursor.execute('SELECT `biol` FROM `allusers` WHERE `user_id` = ?', (user_id,)).fetchall() temp = biol_temp[0] if temp[0] == 0: return self.cursor.execute("UPDATE `allusers` SET `biol` = 1 WHERE `user_id` = ?", (user_id,)) else: return self.cursor.execute("UPDATE `allusers` SET `biol` = 0 WHERE `user_id` = ?", (user_id,)) def close(self): """Закрываем соединение с БД""" self.connection.close()