app.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sat Apr 22 17:07:13 2022
  4. @author: Hammerle
  5. """
  6. import json
  7. import requests
  8. from flask import Flask, render_template
  9. # FOLDER = "src/" # docker
  10. FOLDER = "" # local
  11. app = Flask(__name__)
  12. app.config["TEMPLATES_AUTO_RELOAD"] = True
  13. with open(f"{FOLDER}secret_key", "rb") as secretKeyFile:
  14. app.secret_key = secretKeyFile.read()
  15. @app.route("/", methods=["GET"])
  16. def index():
  17. return render_template("index.html")
  18. @app.route("/karte", methods=["GET"])
  19. def map_():
  20. marker_groups = read_database("map")
  21. return render_template("map.html", marker_groups=marker_groups)
  22. @app.route("/schritte", methods=["GET"])
  23. def steps():
  24. steps = read_database("steps")
  25. return render_template("steps.html", steps=steps)
  26. @app.route("/events", methods=["GET"])
  27. def events():
  28. boudicca_req = requests.get("https://api.boudicca.events/event")
  29. events = []
  30. if boudicca_req.status_code == 200:
  31. events = boudicca_req.json()
  32. return render_template('events.html', events=events)
  33. @app.route("/mitgestaltung", methods=["GET"])
  34. def contribute():
  35. return render_template("contribute.html")
  36. def read_database(name):
  37. with open(f"{FOLDER}database_{name}.json") as file:
  38. db_data = json.load(file)
  39. return db_data
  40. if __name__ == "__main__":
  41. app.run() # localhost
  42. # app.run(host="0.0.0.0") # in network