Добавить main.py
This commit is contained in:
32
main.py
Normal file
32
main.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from flask import Flask, request, jsonify
|
||||
import datetime
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
# Хранилище для истории запросов
|
||||
history = []
|
||||
|
||||
@app.route('/api/store', methods=['POST'])
|
||||
def api():
|
||||
try:
|
||||
data = request.json
|
||||
if not data:
|
||||
return jsonify({"error": "Invalid JSON"}), 400
|
||||
|
||||
# Добавляем данные в историю с меткой времени
|
||||
entry = {
|
||||
"timestamp": datetime.datetime.now().isoformat(),
|
||||
"data": data
|
||||
}
|
||||
history.append(entry)
|
||||
|
||||
return jsonify({"message": "Data received successfully", "data": data}), 200
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@app.route('/api/history', methods=['GET'])
|
||||
def history_endpoint():
|
||||
return jsonify(history), 200
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(debug=True)
|
||||
Reference in New Issue
Block a user