You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
944 B
44 lines
944 B
from flask import Flask, request, jsonify
|
|
import json
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
|
|
DATA_FILE = 'data.json'
|
|
|
|
@app.route('/callback', methods=['POST'])
|
|
def callback():
|
|
data = request.json
|
|
|
|
if not data:
|
|
return jsonify({"error": "Invalid data"}), 400
|
|
|
|
# Read existing data
|
|
if os.path.exists(DATA_FILE):
|
|
with open(DATA_FILE, 'r') as f:
|
|
stored_data = json.load(f)
|
|
else:
|
|
stored_data = []
|
|
|
|
# Append new data
|
|
stored_data.append(data)
|
|
|
|
# Write data back to file
|
|
with open(DATA_FILE, 'w') as f:
|
|
json.dump(stored_data, f, indent=4)
|
|
|
|
return 'Callback received', 200
|
|
|
|
@app.route('/data', methods=['GET'])
|
|
def get_data():
|
|
if os.path.exists(DATA_FILE):
|
|
with open(DATA_FILE, 'r') as f:
|
|
stored_data = json.load(f)
|
|
else:
|
|
stored_data = []
|
|
|
|
return jsonify(stored_data)
|
|
|
|
if __name__ == '__main__':
|
|
app.run(host='0.0.0.0', port=5000)
|