Files
study-task-1/main.py
2025-02-04 16:58:36 +03:00

32 lines
893 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)