Compare commits
2 Commits
639e5ecc2e
...
a3fbd02692
Author | SHA1 | Date | |
---|---|---|---|
|
a3fbd02692 | ||
|
e8bed9a381 |
39
exporto.py
39
exporto.py
@ -1,27 +1,35 @@
|
|||||||
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():
|
||||||
|
|
||||||
|
|
||||||
session = Session()
|
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
|
||||||
|
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
|
||||||
|
dicks_collection = pipisa_db.collection('dicks')
|
||||||
|
|
||||||
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 = dicks_collection.all( )
|
||||||
|
dicks = [[
|
||||||
|
d['user_fullname'],
|
||||||
|
d['dick_size'],
|
||||||
|
d['user_id'],
|
||||||
|
d['chat_id'],
|
||||||
|
d['attempts'],
|
||||||
|
] for d in dicks]
|
||||||
|
|
||||||
|
|
||||||
session.close()
|
return dicks
|
||||||
|
|
||||||
return top
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -36,6 +44,10 @@ 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)):
|
||||||
|
|
||||||
@ -55,6 +67,7 @@ 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()
|
|
@ -1,73 +0,0 @@
|
|||||||
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