From af7f71e10937d22ea01fc6582b777c0f9fe68daa Mon Sep 17 00:00:00 2001 From: Maxime Bloch Date: Fri, 20 Sep 2019 14:15:20 +0200 Subject: [PATCH] Initial commit --- .gitignore | 1 + app.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .gitignore create mode 100644 app.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/app.py b/app.py new file mode 100644 index 0000000..5cac297 --- /dev/null +++ b/app.py @@ -0,0 +1,55 @@ +from flask import Flask +import datetime + +app = Flask(__name__) + +# We request users to send the run number to prevent accidentially getting old requests from a previous run +# This maybe will give to much errors from people forgetting to change their number +# Remove it? + +# TODO +# Save and read from a file to persist over reboots +# Save progress through time during 1 run +# Save result of different runs + +db = { + "current_run": 0, + "run_start_timer": None, + "run_data": { + } + } + +@app.route("/") +def index(): + return "Okay" + +@app.route("/start_run/") +def start_run(run_index): + db["current_run"] = run_index + starttime = datetime.datetime.now() + db["run_data"][run_index] = { + "starttime": starttime, + "data": {} + } + # TODO send start request to the first person in the chain. Probably a zeus part already written as example + return f'Run {run_index} started at {starttime}' + +@app.route("/checkpoint/start//") +def checkpoint_start(run, index): + if db["current_run"] != run: + return "Wrong run number, you are probably behind.", 404 + else: + db["run_data"][run]["data"][index]["start"] = datetime.datetime.now() + return "Success." + + +@app.route("/checkpoint/handoff//") +def checkpoint_handoff(run, index): + if db["current_run"] != run: + return "Wrong run number, you are probably behind.", 404 + else: + db["run_data"][run]["data"][index]["handoff"] = datetime.datetime.now() + return "Success." + +if __name__ == "__main__": + app.run(debug=True)