from ast import Str, While
from cgitb import text
from datetime import date
from multiprocessing import AuthenticationError
from turtle import home
from dnevnikru import Dnevnik
from dnevnikru import exceptions as DnevnikError
from telebot import types
from pprint import pprint
import json
import sqlite3
import telebot
import threading
#sqlite
try:
sqlite_connection = sqlite3.connect('sqlite_python.db', check_same_thread=False)
cursor = sqlite_connection.cursor()
print("База данных создана и успешно подключена к SQLite")
sqlite_select_query = "select sqlite_version();"
cursor.execute(sqlite_select_query)
sqlite_connection.commit()
record = cursor.fetchall()
print("Версия базы данных SQLite: ", record)
except sqlite3.Error as error:
print("Ошибка при подключении к sqlite", error)
finally:
if (sqlite_connection):
sqlite_connection.commit()
print("Соединение с SQLite закрыто")
bot = telebot.TeleBot("5799037534:AAErhJf782SaBMmQgFdllYpPxEXVZC_XL7s")
bot.delete_webhook()
@bot.message_handler(commands=['start', 'go'])
def start_handler(message):
bot.send_message(message.chat.id, "Привет , чтобы войти в дневник ру введи данные в виде логина и пароля (пример: логин123 пароль123) ❗️")
bot.register_next_step_handler(message, auth)
def auth(message):
loginDb, passwordDb = message.text.split()
cursor.execute('INSERT INTO dn (login, password) VALUES (?, ?)', (loginDb, passwordDb))
sqlite_connection.commit()
print(loginDb, passwordDb)
reg(message, loginDb, passwordDb)
bot.register_next_step_handler(message, reg, loginDb, passwordDb)
def reg(message, loginDb, passwordDb):
sqlite_select_query = """SELECT * from dn"""
cursor.execute(sqlite_select_query)
cursor.close
records = cursor.fetchall()
print("Всего строк: ", len(records))
print("Вывод каждой строки")
for row in records:
loginDb = row[0]
passwordDb = row[1]
print("Логин:", row[0])
print("Пароль:", row[1])
d = Dnevnik(login=loginDb, password=passwordDb)
marks = d.marks()
bot.send_message(message.chat.id, ' Вы успешно вошли в аккаунт ' + loginDb)
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton(" Домашняя работа")
btn2 = types.KeyboardButton("оценки")
markup.add(btn1, btn2)
bot.send_message(message.chat.id, 'Выберите в меню действие... ', reply_markup=markup)
marks_message(message, marks)
@bot.message_handler(content_types=['text'])
def marks_message(message, marks):
if message.text.lower() == 'оценки':
for mr in marks:
bot.send_message(message.chat.id, f"{' ' + mr[1] + ':'}\n{' ' + mr[2].translate({ord ('['): None})}")
bot.polling(none_stop=True)
from ast import Str
from cgitb import text
from datetime import date
from multiprocessing import AuthenticationError
from turtle import home
from dnevnikru import Dnevnik
from dnevnikru import exceptions as DnevnikError
from pprint import pprint
import sqlite3
import telebot
#sqlite
try:
sqlite_connection = sqlite3.connect('sqlite_python.db', check_same_thread=False)
cursor = sqlite_connection.cursor()
print("База данных создана и успешно подключена к SQLite")
sqlite_select_query = "select sqlite_version();"
cursor.execute(sqlite_select_query)
sqlite_connection.commit()
record = cursor.fetchall()
print("Версия базы данных SQLite: ", record)
except sqlite3.Error as error:
print("Ошибка при подключении к sqlite", error)
finally:
if (sqlite_connection):
sqlite_connection.commit()
print("Соединение с SQLite закрыто")
bot = telebot.TeleBot("5747148691:AAGo59KswgBCWNs3zmUwaTuPF1cPJnEa_6M")
bot.delete_webhook()
@bot.message_handler(commands=['start', 'go'])
def start_handler(message):
bot.send_message(message.chat.id, "Привет, отправь логин и пароль от дневник.ру")
bot.register_next_step_handler(message, auth)
def auth(message):
loginDb, passwordDb = message.text.split()
cursor.execute('INSERT INTO dn (login, password) VALUES (?, ?)', (loginDb, passwordDb))
sqlite_connection.commit()
print(loginDb, passwordDb)
reg(message, loginDb, passwordDb)
bot.register_next_step_handler(message, reg, loginDb, passwordDb)
def reg(message, loginDb, passwordDb):
sqlite_select_query = """SELECT * from dn"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
print("Всего строк: ", len(records))
print("Вывод каждой строки")
for row in records:
loginDb = row[0]
passwordDb = row[1]
print("Логин:", row[0])
print("Пароль:", row[1])
d = Dnevnik(login=loginDb, password=passwordDb)
print(d)
if message.text == 'Дз':
pprint(d.marks())
bot.polling(non_stop=True)
bot.load_next_step_handlers(loginDb, passwordDb, d, homeworksF)
def homeworksF(message, loginDb, passwordDb, d):
if message.text == 'Дз':
pprint(d.marks())
bot.polling(non_stop=True)