|
@@ -1,19 +1,26 @@
|
|
|
+#!/usr/bin/env python3
|
|
|
+
|
|
|
import json
|
|
|
import atexit
|
|
|
import datetime
|
|
|
|
|
|
from flask import Flask, jsonify, request
|
|
|
+from flask_cors import CORS
|
|
|
|
|
|
DB_FILE = "vacation.db"
|
|
|
|
|
|
last_update = datetime.datetime.now()
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
+CORS(app)
|
|
|
app.config["APPLICATION_ROOT"] = "/vacation/api"
|
|
|
app.url_map.strict_slashes = False
|
|
|
|
|
|
-with open(DB_FILE) as infile:
|
|
|
- db = json.load(infile)
|
|
|
+try:
|
|
|
+ with open(DB_FILE) as infile:
|
|
|
+ db = json.load(infile)
|
|
|
+except FileNotFoundError:
|
|
|
+ db = {}
|
|
|
|
|
|
|
|
|
@atexit.register
|
|
@@ -31,11 +38,13 @@ def health():
|
|
|
return jsonify({"status": "healthy"})
|
|
|
|
|
|
|
|
|
-@app.route("/status", methods=["GET", "POST"])
|
|
|
+@app.route("/availability", methods=["GET", "POST"])
|
|
|
def status():
|
|
|
+ global last_update
|
|
|
+
|
|
|
if request.method == "GET":
|
|
|
return jsonify({
|
|
|
- "lastUpdated": last_update.iso_format(),
|
|
|
+ "lastUpdated": last_update.isoformat(),
|
|
|
"availability": [
|
|
|
{
|
|
|
"name": name,
|
|
@@ -52,4 +61,8 @@ def status():
|
|
|
|
|
|
# TODO actually implement updates
|
|
|
|
|
|
- return 204, ""
|
|
|
+ return "", 204
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ app.run("0.0.0.0", 5000, debug=True)
|