import logging from flask import Flask, request, abort, Response import json app = Flask(__name__) app.logger.setLevel(logging.DEBUG) @app.route('/', methods=['POST']) def record(): if 'file' not in request.files: return abort(400, "no file found") else: soundfile = request.files['file'] if 'description' not in request.form: return abort(400, "no description found") else: description_raw = request.form.get("description") if soundfile.content_type != 'audio/wave': return abort(415, 'Input file not a wave file.') try: desc = json.loads(description_raw) except: return abort(417, 'Input JSON schema invalid') with open("arrived.txt", "at") as f: f.write(f"{desc['device_id']}\n") app.logger.info(f"Arrived: {desc['device_id']}") return Response(status=200) if __name__ == '__main__': app.run(host='0.0.0.0')