Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from flask import Flask, render_template, request, abort, send_from_directory
  2. from dotenv import load_dotenv
  3. from markdown import markdown
  4. from glob import glob
  5. import json
  6. import os
  7. import sys
  8. import time
  9. import shutil
  10. def preprocess_payload(payload):
  11. for column in payload.get("columns", []):
  12. md = column.get("markdown")
  13. if md:
  14. column["content"] = markdown(md)
  15. for slide in column.get("slides", []):
  16. md = slide.get("markdown")
  17. if md:
  18. slide["content"] = markdown(md)
  19. load_dotenv()
  20. application = Flask(__name__)
  21. @application.get("/")
  22. def home():
  23. payload = json.load(open("static/slides.json"))
  24. preprocess_payload(payload)
  25. return render_template("slides.html", **payload)
  26. @application.post("/update")
  27. def update():
  28. shutil.copy(
  29. "static/slides.json",
  30. time.strftime(
  31. "archive/slides-%Y-%m-%d-%H.%M.%S.json",
  32. time.localtime()))
  33. payload = request.get_json()
  34. print(type(payload))
  35. json.dump(payload, sys.stdout, indent=4)
  36. json.dump(payload, open("static/slides.json", "w"), indent=4)
  37. return({"status": "success"})
  38. @application.get("/enum/<topic>")
  39. def choices(topic):
  40. if topic in ["img", "bg"]:
  41. return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
  42. abort(404)
  43. @application.get("/schema.json")
  44. def schema():
  45. return render_template("slides.schema.json", backgrounds=choices("bg"))
  46. @application.get("/editor")
  47. def editor():
  48. return render_template("editor.html")
  49. @application.route("/favicon.ico")
  50. def favicon():
  51. return send_from_directory(os.path.join(application.root_path, "static"),
  52. "favicon.ico", mimetype="image/vnd.microsoft.icon")