pipisa-exporter/exporto.py

73 lines
1.9 KiB
Python
Raw Normal View History

2023-06-20 21:10:25 +10:00
from flask import Flask
2023-07-13 18:25:01 +10:00
#### https://docs.python-arango.com/en/main/
from arango import ArangoClient
2023-06-20 21:10:04 +10:00
2023-07-13 18:25:01 +10:00
app = Flask(__name__)
2023-06-20 21:10:04 +10:00
2023-07-13 18:25:01 +10:00
2023-06-20 21:10:04 +10:00
def get_top_dicks():
2023-07-13 18:25:01 +10:00
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
dicks_collection = pipisa_db.collection('dicks')
2023-06-20 21:10:04 +10:00
2023-07-13 18:25:01 +10:00
dicks = dicks_collection.all( )
dicks = [[
d['user_fullname'],
d['dick_size'],
d['user_id'],
d['chat_id'],
d['attempts'],
] for d in dicks]
2023-06-20 21:10:04 +10:00
2023-07-13 18:25:01 +10:00
return dicks
2023-06-20 21:10:04 +10:00
2023-06-21 12:33:09 +10:00
2023-06-21 12:24:29 +10:00
2023-06-21 12:33:09 +10:00
@app.route('/metrics')
def metrics():
metrics = ""
2023-06-21 12:30:26 +10:00
2023-06-21 12:33:09 +10:00
docks = get_top_dicks()
2023-06-21 12:30:26 +10:00
2023-06-21 12:33:09 +10:00
# текущий размер пипис
for dick in docks:
2023-07-13 18:25:01 +10:00
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])
2023-06-21 12:24:29 +10:00
2023-06-21 12:33:09 +10:00
# расстояние до следующего впереди
for k in range(len(docks)):
2023-06-21 12:30:26 +10:00
2023-06-21 12:33:09 +10:00
### не самый красивый код для не самой красивой ситуации
2023-06-21 12:30:26 +10:00
2023-06-21 12:33:09 +10:00
if k == 0:
metrics += 'pipisio_topdick_distanso{user="%s", user_id="%s", chat_id="%s"} %s\n' % (docks[k][0], docks[k][2], docks[k][3], 0)
else:
i = k - 1
upper_dick_size = docks[i][1]
while i > 0 and upper_dick_size == docks[k][1]:
i -= 1
upper_dick_size = docks[i][1]
metrics += 'pipisio_topdick_distanso{user="%s", user_id="%s", chat_id="%s"} %s\n' % (docks[k][0], docks[k][2], docks[k][3], (upper_dick_size - docks[k][1]))
2023-06-21 12:30:26 +10:00
2023-06-21 12:33:09 +10:00
return metrics
2023-06-20 21:10:04 +10:00
2023-07-13 18:25:01 +10:00
2023-06-21 12:33:09 +10:00
if __name__ == '__main__':
2023-07-13 18:25:01 +10:00
app.run(host='0.0.0.0', port=9992)