Spaces:
Sleeping
Sleeping
import flask | |
from flask import request, jsonify, send_file | |
import os | |
import json | |
from dotenv import load_dotenv | |
load_dotenv() | |
app = flask.Flask(__name__) | |
app.config["DEBUG"] = True | |
def index(): | |
return ''' | |
<html> | |
<body> | |
<h1>Привет, Мир!</h1> | |
<p>Это моя страница.</p> | |
</body> | |
</html> | |
''' | |
def avp(): | |
try: | |
# Получение JSON-данных из запроса | |
incoming = request.get_json() | |
print(incoming) | |
result = {} | |
for key, value in incoming.items(): | |
if int(value) > 0: | |
result[key] = str(int(value) - 1) | |
else: | |
result[key] = value | |
# Сохранение результата в файл | |
with open("output.json", "w") as file: | |
json.dump(result, file) | |
# Возвращение файла клиенту | |
return send_file("output.json", as_attachment=True) | |
except Exception as e: | |
error_response = { | |
"error": str(e) | |
} | |
return jsonify(error_response), 500 | |
if __name__ == '__main__': | |
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860))) |