示例#1
0
        data_logger.add_item(**item)
    except ItemExistsError as e:
        abort(make_error_response(e.message, 422))

    return jsonify(item), 201


@app.route("/items/<name>", methods=["DELETE"])
def delete_item(name):
    """delete the item with the given name"""
    global data_logger
    try:
        data_logger.delete_item(name)
        return jsonify({"result": True})
    except KeyError as e:
        return make_error_response(e.message, 404)


if __name__ == "__main__":
    data_logger.load_config("data_logger_config.json")

    # run the data logger in a thread, concurrently with the Flask service app
    data_logger_thread = Thread(target=data_logger.run)
    # We haven't implemented a way to stop the data logger yet so make it
    # a daemon thread so it quits immediately when the main thread stops.
    data_logger_thread.daemon = True
    data_logger_thread.start()

    # run the flask app in the main thread
    app.run(debug=True)