From 2015338c74807314c0a4d66703c888141fd9224a Mon Sep 17 00:00:00 2001 From: Alex Danamir Date: Sat, 17 Dec 2022 15:08:19 +0300 Subject: [PATCH] add bot func --- app.py | 15 +++++++++++ bot.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ models.py | 14 ++++++++++ 3 files changed, 107 insertions(+) create mode 100644 app.py create mode 100644 bot.py create mode 100644 models.py diff --git a/app.py b/app.py new file mode 100644 index 0000000..704c6d0 --- /dev/null +++ b/app.py @@ -0,0 +1,15 @@ +from flask import Flask, render_template, request +import logging + +logging.basicConfig(filename='app.log', encoding='utf-8', level=logging.DEBUG) +from models import db, ArtDavl + + +def create_app(): + app = Flask(__name__) + app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db' + app.secret_key ='6523e58bc0eec42c31b9635d5e0dfc23b6d119b73e633bf3a5284c79bb4a1ede' + db.init_app(app) + + return app + diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..78ce840 --- /dev/null +++ b/bot.py @@ -0,0 +1,78 @@ +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) diff --git a/models.py b/models.py new file mode 100644 index 0000000..e2e6d25 --- /dev/null +++ b/models.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from flask_sqlalchemy import SQLAlchemy + +db = SQLAlchemy() + +class ArtDavl(db.Model): + id = db.Column(db.Integer, primary_key=True, autoincrement=True) + davlh = db.Column(db.Integer()) + davll = db.Column(db.Integer()) + puls = db.Column(db.Integer()) + sostoyanie = db.Column(db.String(11)) + dateadd = db.Column(db.String(11)) + timeadd = db.Column(db.String(11)) \ No newline at end of file