научился записывать id

This commit is contained in:
Pavel_Duron 2022-11-11 18:18:16 +10:00
parent 0c15876deb
commit e32c1dc991
6 changed files with 41 additions and 12 deletions

16
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,16 @@
{
// Используйте IntelliSense, чтобы узнать о возможных атрибутах.
// Наведите указатель мыши, чтобы просмотреть описания существующих атрибутов.
// Для получения дополнительной информации посетите: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: текущий файл",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": true
}
]
}

Binary file not shown.

Binary file not shown.

21
bot.py
View File

@ -2,10 +2,13 @@ from cgitb import text
import datetime import datetime
import logging import logging
from random import randint from random import randint
#from sqdb import tert from sqlalchemy import create_engine, MetaData, Table, Integer, String, \
Column, DateTime, ForeignKey, Numeric
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from aiogram import Bot, Dispatcher, executor, types from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton from aiogram.types import ReplyKeyboardRemove, ReplyKeyboardMarkup, KeyboardButton
from sqdb import user
@ -46,12 +49,22 @@ async def dick(message: types.Message):
numb = (f"Рандомное число : {randint(-7,10)}") numb = (f"Рандомное число : {randint(-7,10)}")
await bot.send_message(message.chat.id, (numb)) await bot.send_message(message.chat.id, (numb))
@dp.message_handler(commands=["id"]) @dp.message_handler(commands=["id"])
async def ident(message: types.Message): async def ident(message: types.Message):
# работа с таблицей
engine = create_engine('sqlite:///dick3.db')
Session = sessionmaker(bind=engine)
session = Session()
Base = declarative_base()
int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name) #импортирую юзер из sqdb
session.add(int_table)
session.commit()
await bot.send_message(message.chat.id, f'{message.from_user.id} + {message.from_user.full_name}') await bot.send_message(message.chat.id, f'{message.from_user.id} + {message.from_user.full_name}')
# lisq = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name)
# tert.adding()

BIN
dick3.db

Binary file not shown.

12
sqdb.py
View File

@ -2,6 +2,7 @@ from sqlalchemy import create_engine, MetaData, Table, Integer, String, \
Column, DateTime, ForeignKey, Numeric Column, DateTime, ForeignKey, Numeric
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///dick3.db') engine = create_engine('sqlite:///dick3.db')
Session = sessionmaker(bind=engine) Session = sessionmaker(bind=engine)
session = Session() session = Session()
@ -20,13 +21,13 @@ class user(Base):
user_fullname = Column(String) user_fullname = Column(String)
#list = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name) # list = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name)
class tert:
def adding():
session.add(lisq) def adding():
session.add()
session.commit() session.commit()
@ -38,5 +39,4 @@ class tert:
listq2 = bot.ident.lisq()
print(listq2)