Anders and Briegel in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

50 wiersze
1.2KB

  1. from flask import Flask, request, render_template, jsonify
  2. import json
  3. import abp
  4. graphstate = abp.GraphState()
  5. app = Flask(__name__)
  6. @app.route("/")
  7. def index():
  8. return render_template("index.html")
  9. @app.route("/state", methods = ["GET", "POST"])
  10. def state():
  11. if request.method == "GET":
  12. return jsonify(graphstate.to_json())
  13. elif request.method == "POST":
  14. graphstate.from_json(json.loads(request.data))
  15. return jsonify(graphstate.to_json())
  16. @app.route("/add/<int:node>")
  17. def add(node):
  18. """ Add a node to the graph """
  19. graphstate.add_node(node)
  20. return jsonify(graphstate.to_json())
  21. @app.route("/rotate/<int:node>/<int:operation>")
  22. def rotate(node):
  23. """ Add a node to the graph """
  24. graphstate.act_local_rotation(node, operation)
  25. return jsonify(graphstate.to_json())
  26. @app.route("/cz/<int:a>/<int:b>")
  27. def cz(a, b):
  28. """ Add a node to the graph """
  29. graphstate.act_cz(a, b)
  30. return jsonify(graphstate.to_json())
  31. @app.route("/clear")
  32. def clear():
  33. """ Clear the current state """
  34. graphstate = abp.GraphState()
  35. return jsonify({"clear": "ok"})
  36. if __name__ == "__main__":
  37. app.debug = True
  38. app.run(host="0.0.0.0")