add stats

This commit is contained in:
Administrator 2023-11-12 17:59:22 +03:00
parent c3b189c57b
commit 0ba5ef0789
4 changed files with 71 additions and 1 deletions

View File

@ -5,6 +5,7 @@ services:
bot:
image: mathwave/sprint-repo:pizda-bot
command: bot
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
MONGO_HOST: "mongo.develop.sprinthub.ru"
@ -18,3 +19,26 @@ services:
update_config:
parallelism: 1
order: start-first
pizda-bot-nginx:
image: mathwave/sprint-repo:pizda-bot
command: api
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
STAGE: "development"
networks:
- common-infra-nginx
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
networks:
common-infra-nginx:
external: true

View File

@ -5,6 +5,7 @@ services:
bot:
image: mathwave/sprint-repo:pizda-bot
command: bot
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
MONGO_HOST: "mongo.sprinthub.ru"
@ -18,3 +19,26 @@ services:
update_config:
parallelism: 1
order: start-first
pizda-bot-nginx:
image: mathwave/sprint-repo:pizda-bot
command: api
environment:
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
STAGE: "production"
networks:
- common-infra-nginx
deploy:
mode: replicated
restart_policy:
condition: any
update_config:
parallelism: 1
order: start-first
networks:
common-infra-nginx:
external: true

16
api.py Normal file
View File

@ -0,0 +1,16 @@
from flask import Flask
from 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
}

View File

@ -1,4 +1,5 @@
import os
import sys
from random import randrange, choice
import telebot
@ -178,4 +179,9 @@ def do_action(message: Message):
mongo.inc(message.from_user.username, message.chat.id)
bot.polling()
arg = sys.argv[-1]
if arg == 'bot':
bot.polling()
else:
from api import app
app.run(host="0.0.0.0", port=1238)