DmitrMakeev
commited on
Commit
•
3b33a44
1
Parent(s):
8645bf0
Update app.py
Browse files
app.py
CHANGED
@@ -1,51 +1,20 @@
|
|
1 |
import flask
|
2 |
-
from flask import request, jsonify
|
3 |
import os
|
4 |
import json
|
5 |
from dotenv import load_dotenv
|
6 |
-
|
7 |
load_dotenv()
|
8 |
-
|
9 |
-
app
|
10 |
-
app.config["DEBUG"] = True
|
11 |
-
|
12 |
-
@app.route('/', methods=['GET'])
|
13 |
def index():
|
14 |
-
return ''
|
15 |
-
<html>
|
16 |
-
<body>
|
17 |
-
<h1>Привет, Мир!</h1>
|
18 |
-
<p>Это моя страница.</p>
|
19 |
-
</body>
|
20 |
-
</html>
|
21 |
-
'''
|
22 |
|
23 |
@app.route("/avp", methods=["POST"])
|
24 |
def avp():
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
result = {}
|
31 |
-
for key, value in incoming.items():
|
32 |
-
if int(value) > 0:
|
33 |
-
result[key] = str(int(value) - 1)
|
34 |
-
else:
|
35 |
-
result[key] = value
|
36 |
-
|
37 |
-
# Сохранение результата в файл
|
38 |
-
with open("output.json", "w") as file:
|
39 |
-
json.dump(result, file)
|
40 |
-
|
41 |
-
# Возвращение файла клиенту
|
42 |
-
return send_file("output.json", as_attachment=True)
|
43 |
-
|
44 |
-
except Exception as e:
|
45 |
-
error_response = {
|
46 |
-
"error": str(e)
|
47 |
-
}
|
48 |
-
return jsonify(error_response), 500
|
49 |
-
|
50 |
if __name__ == '__main__':
|
51 |
-
app.run(host='0.0.0.0',
|
|
|
1 |
import flask
|
2 |
+
from flask import request, jsonify
|
3 |
import os
|
4 |
import json
|
5 |
from dotenv import load_dotenv
|
|
|
6 |
load_dotenv()
|
7 |
+
app = flask.Flask(__name__, template_folder="./")
|
8 |
+
@app.route('/')
|
|
|
|
|
|
|
9 |
def index():
|
10 |
+
return flask.render_template('index.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
@app.route("/avp", methods=["POST"])
|
13 |
def avp():
|
14 |
+
incoming = request.get_json()
|
15 |
+
print(incoming)
|
16 |
+
# Обработка POST запроса по пути "/avp"
|
17 |
+
response = {"bazis": incoming["bazis"]}
|
18 |
+
return jsonify(response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
if __name__ == '__main__':
|
20 |
+
app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
|