add admin
This commit is contained in:
parent
0f16bff9ac
commit
14d87bed02
@ -26,6 +26,30 @@ services:
|
|||||||
parallelism: 1
|
parallelism: 1
|
||||||
order: start-first
|
order: start-first
|
||||||
|
|
||||||
|
roulette-nginx:
|
||||||
|
image: mathwave/sprint-repo:roulette-bot
|
||||||
|
command: bot
|
||||||
|
environment:
|
||||||
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_DEV
|
||||||
|
MONGO_HOST: "mongo.develop.sprinthub.ru"
|
||||||
|
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
|
||||||
|
MINIO_HOST: "minio.develop.sprinthub.ru"
|
||||||
|
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_DEV
|
||||||
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
|
STAGE: "development"
|
||||||
|
REDIS_HOST: "redis.develop.sprinthub.ru"
|
||||||
|
REDIS_PASSWORD: $REDIS_PASSWORD_DEV
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
|
- common-infra-nginx
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
restart_policy:
|
||||||
|
condition: any
|
||||||
|
update_config:
|
||||||
|
parallelism: 1
|
||||||
|
order: start-first
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
net:
|
net:
|
||||||
driver: overlay
|
driver: overlay
|
||||||
|
@ -4,6 +4,29 @@ version: "3.4"
|
|||||||
services:
|
services:
|
||||||
|
|
||||||
bot:
|
bot:
|
||||||
|
image: mathwave/sprint-repo:roulette-bot
|
||||||
|
command: bot
|
||||||
|
networks:
|
||||||
|
- net
|
||||||
|
environment:
|
||||||
|
TELEGRAM_TOKEN: $TELEGRAM_TOKEN_PROD
|
||||||
|
MONGO_HOST: "mongo.sprinthub.ru"
|
||||||
|
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
|
||||||
|
MINIO_HOST: "minio.sprinthub.ru"
|
||||||
|
MINIO_SECRET_KEY: $MINIO_SECRET_KEY_PROD
|
||||||
|
PLATFORM_SECURITY_TOKEN: $PLATFORM_SECURITY_TOKEN
|
||||||
|
STAGE: "production"
|
||||||
|
REDIS_HOST: "redis.sprinthub.ru"
|
||||||
|
REDIS_PASSWORD: $REDIS_PASSWORD_PROD
|
||||||
|
deploy:
|
||||||
|
mode: replicated
|
||||||
|
restart_policy:
|
||||||
|
condition: any
|
||||||
|
update_config:
|
||||||
|
parallelism: 1
|
||||||
|
order: start-first
|
||||||
|
|
||||||
|
roulette-nginx:
|
||||||
image: mathwave/sprint-repo:roulette-bot
|
image: mathwave/sprint-repo:roulette-bot
|
||||||
command: bot
|
command: bot
|
||||||
networks:
|
networks:
|
||||||
|
96
api.py
Normal file
96
api.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import io
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
from bson import ObjectId
|
||||||
|
from flask import Flask, Response, request, redirect, jsonify, send_file
|
||||||
|
from minio import Minio, S3Error
|
||||||
|
from telebot.apihelper import ApiTelegramException
|
||||||
|
|
||||||
|
import settings
|
||||||
|
from api_processors import steps_dict
|
||||||
|
from mongo import mongo
|
||||||
|
|
||||||
|
|
||||||
|
app = Flask("roulette")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/letsgonumber')
|
||||||
|
def step():
|
||||||
|
number = request.args.get('num')
|
||||||
|
action = steps_dict[int(number)]
|
||||||
|
for chat in mongo.chats_collection.find({}):
|
||||||
|
try:
|
||||||
|
action(chat)
|
||||||
|
except ApiTelegramException as e:
|
||||||
|
print(e)
|
||||||
|
sleep(.2)
|
||||||
|
return redirect('/adminkadlyapazanov')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/adminkadlyapazanov')
|
||||||
|
def index():
|
||||||
|
return Response('''
|
||||||
|
<html>
|
||||||
|
<head></head>
|
||||||
|
<body>
|
||||||
|
<a href="/letsgonumber?num=1">Приветствие</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=2">Спокойной ночи</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=3">Доброе утро</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=4">Квиз 1</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=5">Время фото</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=6">Музло</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=7">Квиз 2</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=8">Открытки</a><br><br><br>
|
||||||
|
<a href="/letsgonumber?num=9">Промокоды</a><br><br><br>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/info')
|
||||||
|
def info():
|
||||||
|
s = "<html><head></head><body>"
|
||||||
|
for chat in mongo.chats_collection.find({}):
|
||||||
|
for key, value in chat.items():
|
||||||
|
s += f"{key}: {value}<br>"
|
||||||
|
s += f"<img src=\"/photo?chat_id={chat['chat_id']}\"/><br><hr>"
|
||||||
|
return Response(s)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/photo')
|
||||||
|
def photo():
|
||||||
|
chat_id = int(request.args.get('chat_id'))
|
||||||
|
doc = mongo.chats_collection.find_one({"chat_id": chat_id})
|
||||||
|
client = Minio(
|
||||||
|
settings.MINIO_HOST,
|
||||||
|
access_key=settings.MINIO_ACCESS_KEY,
|
||||||
|
secret_key=settings.MINIO_SECRET_KEY,
|
||||||
|
secure=False
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
data = client.get_object(
|
||||||
|
"8march-bot",
|
||||||
|
f"selfies/{chat_id}-{doc['username']}-{doc['telegram_name']}.jpg",
|
||||||
|
).data
|
||||||
|
except S3Error:
|
||||||
|
data = open('shrek.jpeg', 'rb').read()
|
||||||
|
return send_file(io.BytesIO(data), mimetype='image/jpg')
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/dialogs')
|
||||||
|
def main():
|
||||||
|
html = "<html><head></head><body>"
|
||||||
|
for dialog in mongo.dialogs_collection.find({}).sort([('started_at', -1)]):
|
||||||
|
html += f'<a href="/dialog?id={dialog["_id"]}">{dialog["_id"]}</a><br>'
|
||||||
|
html += "</body></html>"
|
||||||
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/dialog')
|
||||||
|
def dialog():
|
||||||
|
html = "<html><head></head><body>"
|
||||||
|
for message in mongo.messages_collection.find({"dialog_id": ObjectId(request.args.get('dialog_id'))}).sort([('sent_at', 1)]):
|
||||||
|
html += f'{message["sender"]}: {message["text"]}<br>'
|
||||||
|
html += "</body></html>"
|
||||||
|
return html
|
3
main.py
3
main.py
@ -4,5 +4,8 @@ import sys
|
|||||||
if sys.argv[-1] == "bot":
|
if sys.argv[-1] == "bot":
|
||||||
from bot import run_bot
|
from bot import run_bot
|
||||||
run_bot()
|
run_bot()
|
||||||
|
elif sys.argv[-1] == "api":
|
||||||
|
from api import app
|
||||||
|
app.run(host="0.0.0.0", port=1238)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
@ -23,6 +23,9 @@ class Mongo:
|
|||||||
("chat_id_2", 1),
|
("chat_id_2", 1),
|
||||||
('finished_at', 1)
|
('finished_at', 1)
|
||||||
])
|
])
|
||||||
|
self.messages_collection.create_index([
|
||||||
|
('dialog_id', 1)
|
||||||
|
])
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return self.database.get_collection(item)
|
return self.database.get_collection(item)
|
||||||
|
Loading…
Reference in New Issue
Block a user