DmitrMakeev commited on
Commit
3b33a44
1 Parent(s): 8645bf0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -41
app.py CHANGED
@@ -1,51 +1,20 @@
1
  import flask
2
- from flask import request, jsonify, send_file
3
  import os
4
  import json
5
  from dotenv import load_dotenv
6
-
7
  load_dotenv()
8
-
9
- app = flask.Flask(__name__)
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
- try:
26
- # Получение JSON-данных из запроса
27
- incoming = request.get_json()
28
- print(incoming)
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', port=int(os.environ.get('PORT', 7860)))
 
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)))