From 5b76f3528c99c71fa37d08390dcbe178b7405e98 Mon Sep 17 00:00:00 2001 From: Administrator Date: Sat, 22 Oct 2022 13:06:59 +0300 Subject: [PATCH] api --- .deploy/deploy-dev.yaml | 21 +++++++++++++++++++++ daemons/api.py | 18 ++++++++++++++++++ entrypoint.py | 4 ++++ requirements.txt | 6 ++++++ 4 files changed, 49 insertions(+) create mode 100644 daemons/api.py diff --git a/.deploy/deploy-dev.yaml b/.deploy/deploy-dev.yaml index 919ee0f..9022783 100644 --- a/.deploy/deploy-dev.yaml +++ b/.deploy/deploy-dev.yaml @@ -47,3 +47,24 @@ services: update_config: parallelism: 1 order: start-first + + api: + image: mathwave/sprint-repo:ruz-bot + networks: + - common-infra-nginx + environment: + MONGO_HOST: "mongo.develop.sprinthub.ru" + MONGO_PASSWORD: $MONGO_PASSWORD_DEV + TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV + command: api + deploy: + mode: replicated + restart_policy: + condition: any + update_config: + parallelism: 1 + order: start-first + +networks: + common-infra-nginx: + external: true diff --git a/daemons/api.py b/daemons/api.py new file mode 100644 index 0000000..eafce96 --- /dev/null +++ b/daemons/api.py @@ -0,0 +1,18 @@ +from flask import Flask + +import settings +from helpers.mongo import mongo + + +def api(): + app = Flask(__name__) + + @app.route('/stats', methods=['GET']) + def stats(): + return { + "Всего пользователей": mongo.users_collection.count_documents({}), + "Подписано на уведомления": mongo.users_collection.count_documents({"notify_minutes": {"$ne": None}}), + "Отправлено уведомлений за сегодня": mongo.lessons_collection.count_documents({"notified": True}) + } + + app.run(host="0.0.0.0", port=1238, debug=settings.DEBUG) diff --git a/entrypoint.py b/entrypoint.py index c87ae76..4f56b50 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -1,5 +1,6 @@ import sys +from daemons.api import api from daemons.bot import bot from daemons.fetch import fetch from daemons.notify import notify @@ -15,5 +16,8 @@ elif arg == "fetch": elif arg == "notify": print("notify is starting") notify() +elif arg == "api": + print("api is starting") + api() else: raise ValueError(f"Unknown param {arg}") diff --git a/requirements.txt b/requirements.txt index 0ee2fda..c1ebfb5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,11 @@ certifi==2022.9.24 charset-normalizer==2.1.1 +click==8.1.3 +Flask==2.2.2 idna==3.4 +itsdangerous==2.1.2 +Jinja2==3.1.2 +MarkupSafe==2.1.1 marshmallow==3.18.0 marshmallow-dataclass==8.5.9 mypy-extensions==0.4.3 @@ -15,3 +20,4 @@ six==1.16.0 typing-inspect==0.8.0 typing_extensions==4.4.0 urllib3==1.26.12 +Werkzeug==2.2.2