This commit is contained in:
parent
8d684856c9
commit
639e5ecc2e
24
exporto.py
24
exporto.py
@ -2,7 +2,7 @@ from sqlalchemy import create_engine, Integer, String, BIGINT, Column, DateTime
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker
|
||||
from sqlalchemy import select, update
|
||||
|
||||
from sql_db_data import *
|
||||
|
||||
|
||||
from flask import Flask
|
||||
@ -10,33 +10,13 @@ from flask import Flask
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
engine = create_engine('postgresql+psycopg2://postgres:postgres@postgres.vdk2ch.ru:5432/jack_bot', echo=True)
|
||||
Session = sessionmaker(bind=engine)
|
||||
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
|
||||
class user(Base):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer)
|
||||
user_fullname = Column(String)
|
||||
dick_size = (Column(Integer))
|
||||
datetimes = (Column(DateTime))
|
||||
chat_id = Column(BIGINT)
|
||||
|
||||
|
||||
|
||||
|
||||
def get_top_dicks():
|
||||
|
||||
|
||||
session = Session()
|
||||
|
||||
top = session.query(user.user_fullname, user.dick_size, user.user_id, user.chat_id).order_by(user.dick_size.desc()).all()
|
||||
top = session.query(User.user_fullname, UserDick.dick_size, User.user_id, UserDick.chat_id).join(UserDick).order_by(UserDick.dick_size.desc()).all()
|
||||
|
||||
|
||||
session.close()
|
||||
|
6
requirements.txt
Normal file
6
requirements.txt
Normal file
@ -0,0 +1,6 @@
|
||||
aiogram
|
||||
sqdb
|
||||
sqlalchemy
|
||||
graypy
|
||||
flask
|
||||
psycopg2
|
73
sql_db_data.py
Normal file
73
sql_db_data.py
Normal file
@ -0,0 +1,73 @@
|
||||
from sqlalchemy import create_engine, MetaData, Table, Integer, String, BIGINT, \
|
||||
Column, DateTime, ForeignKey, Numeric
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
from sqlalchemy import select, update
|
||||
|
||||
engine = create_engine('postgresql+psycopg2://postgres:postgres@postgres.vdk2ch.ru:5432/jack_bot', echo=True)
|
||||
Session = sessionmaker(bind=engine)
|
||||
session = Session()
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = 'users'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer)
|
||||
date_created = (Column(DateTime))
|
||||
user_fullname = Column(String)
|
||||
date_updated = (Column(DateTime))
|
||||
dick_requests = relationship("DickRequest", back_populates="user")
|
||||
user_dicks = relationship("UserDick", back_populates="user")
|
||||
|
||||
|
||||
class UserDick(Base):
|
||||
__tablename__ = 'user_dicks'
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey("users.user_id"))
|
||||
dick_size = (Column(Integer))
|
||||
chat_id = Column(BIGINT)
|
||||
user = relationship("User", back_populates="user_dicks")
|
||||
|
||||
|
||||
class DickRequest(Base):
|
||||
__tablename__ = 'dick_requests'
|
||||
id = Column(Integer, primary_key=True)
|
||||
size_change = Column(Integer)
|
||||
user_id = Column(Integer, ForeignKey("users.user_id"))
|
||||
user = relationship("User", back_populates="dick_requests")
|
||||
date_changed = (Column(DateTime))
|
||||
|
||||
|
||||
session.close()
|
||||
engine.dispose()
|
||||
|
||||
# top = session.query(user.user_fullname, user.dick_size)
|
||||
# .order_by(user.dick_size.desc())
|
||||
# .filter(user.chat_id == user.chat_id).limit(10).all()
|
||||
# print(top)
|
||||
|
||||
|
||||
# Base.metadata.create_all(engine)
|
||||
|
||||
# int_table = user(user_id = 12345678, user_fullname = 'test', dick_size = 10) #импортирую юзер из sqdb
|
||||
# session.add(int_table)
|
||||
# session.commit()
|
||||
# select user_id, name from employees limit 10
|
||||
|
||||
# def adding():
|
||||
|
||||
# session.add()
|
||||
# session.commit()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user