34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from collections import defaultdict
|
||
|
||
from flask import Flask
|
||
|
||
from utils.mongo import mongo
|
||
|
||
app = Flask(__name__)
|
||
|
||
|
||
@app.route('/stats/json', methods=['GET'])
|
||
def stats_json():
|
||
replies = 0
|
||
for doc in mongo.counter_collection.find({}):
|
||
replies += doc['count']
|
||
return {
|
||
"Всего чатов": mongo.chats_collection.count_documents({"chat_id": {"$lt": 0}}),
|
||
"Отвечено": replies
|
||
}
|
||
|
||
|
||
@app.route('/rating', methods=['GET'])
|
||
def main():
|
||
rating = defaultdict(int)
|
||
for doc in mongo.counter_collection.find({"username": {"$ne": None}}):
|
||
rating[doc["username"]] += doc['count']
|
||
rating_list = []
|
||
for user, count in rating.items():
|
||
rating_list.append({'username': user, 'count': count})
|
||
page = '<html><body><h1>Рейтинг затроленных</h1><br><ul>'
|
||
for item in sorted(rating_list, key=lambda x: x['count'], reverse=True):
|
||
page += f'<li><a target="_blank" href="https://t.me/{item["username"]}">{item["username"]}</a> - {item["count"]}</li>'
|
||
page += '</ul></body></html>'
|
||
return page
|