Compare commits

..

No commits in common. "a3fbd0269247f6ae1548d8436f73a72221a60bb1" and "639e5ecc2ea3b3c592b3aaf8b53753476b9b2ec5" have entirely different histories.

3 changed files with 89 additions and 28 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
Оно собирает хуи!

View File

@ -1,35 +1,27 @@
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 from flask import Flask
#### https://docs.python-arango.com/en/main/
from arango import ArangoClient
app = Flask(__name__) app = Flask(__name__)
def get_top_dicks(): def get_top_dicks():
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru') session = Session()
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
dicks_collection = pipisa_db.collection('dicks')
dicks = dicks_collection.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()
dicks = [[
d['user_fullname'],
d['dick_size'],
d['user_id'],
d['chat_id'],
d['attempts'],
] for d in dicks]
return dicks session.close()
return top
@ -44,10 +36,6 @@ def metrics():
for dick in docks: for dick in docks:
metrics += 'pipisio{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[1]) metrics += 'pipisio{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[1])
# текущее число попыток
for dick in docks:
metrics += 'pipisio_attempto{user="%s", user_id="%s", chat_id="%s"} %s\n' % (dick[0], dick[2], dick[3], dick[4])
# расстояние до следующего впереди # расстояние до следующего впереди
for k in range(len(docks)): for k in range(len(docks)):
@ -67,7 +55,6 @@ def metrics():
return metrics return metrics
if __name__ == '__main__': if __name__ == '__main__':
app.run(host='0.0.0.0', port=9992) app.run(host='0.0.0.0', port=9992)
engine.dispose()

73
sql_db_data.py Normal file
View 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()