79 lines
2.2 KiB
Python
79 lines
2.2 KiB
Python
import logging
|
|
from flask import Flask
|
|
from aiogram import Bot, Dispatcher, executor, types
|
|
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
|
|
from aiogram.dispatcher.filters import Text
|
|
from models import ArtDavl, db
|
|
from datetime import datetime
|
|
|
|
from app import create_app
|
|
|
|
|
|
API_TOKEN = '5865694626:AAHBUoBSNW0C3_Tzfj7iZQ-6pWiNI64r-Lo'
|
|
|
|
|
|
logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG, datefmt='%H:%M:%S')
|
|
|
|
bot = Bot(token=API_TOKEN)
|
|
|
|
dp = Dispatcher(bot)
|
|
|
|
|
|
@dp.message_handler(commands=['start', 'help'])
|
|
async def send_welcome(message: types.Message):
|
|
button1 = KeyboardButton(text='Очень плохо')
|
|
button2 = KeyboardButton(text='Плохо')
|
|
button3 = KeyboardButton(text='Хорошо')
|
|
button4 = KeyboardButton(text='Очень хорошо')
|
|
|
|
markup = ReplyKeyboardMarkup(resize_keyboard=True).add(button1, button2, button3, button4)
|
|
|
|
|
|
"""
|
|
|
|
This handler will be called when user sends `/start` or `/help` command
|
|
|
|
"""
|
|
|
|
await message.answer("Привет! Этот бот предназначен для дневника артериального давления. \n\
|
|
Введите давление и пульс в формате 123 12 12", reply_markup=markup)
|
|
|
|
|
|
|
|
@dp.message_handler()
|
|
async def echo(message: types.Message):
|
|
button1 = KeyboardButton(text='Очень плохо')
|
|
button2 = KeyboardButton(text='Плохо')
|
|
button3 = KeyboardButton(text='Хорошо')
|
|
button4 = KeyboardButton(text='Очень хорошо')
|
|
|
|
markup = ReplyKeyboardMarkup(resize_keyboard=True).add(button1, button2, button3, button4)
|
|
|
|
|
|
|
|
|
|
davl = str(message.text).split()
|
|
|
|
if
|
|
logging.debug(davl)
|
|
|
|
|
|
|
|
app = create_app()
|
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'
|
|
with app.app_context():
|
|
|
|
wtdb = ArtDavl(davlh=davl[0],
|
|
davll=davl[1], puls=davl[2],
|
|
sostoyanie="OTL",
|
|
dateadd=datetime.now().strftime('%d.%m.%Y'),
|
|
timeadd=datetime.now().strftime('%H:%M'))
|
|
db.session.add(wtdb)
|
|
db.session.commit()
|
|
|
|
await message.answer("Сообщение получено",reply_markup=markup)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
executor.start_polling(dp, skip_updates=True)
|