add bot func
This commit is contained in:
15
app.py
Normal file
15
app.py
Normal file
@@ -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
|
||||||
|
|
||||||
78
bot.py
Normal file
78
bot.py
Normal file
@@ -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)
|
||||||
14
models.py
Normal file
14
models.py
Normal file
@@ -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))
|
||||||
Reference in New Issue
Block a user