Simulate graph states in the browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
811B

  1. from flask import Flask, request, redirect, url_for, make_response, render_template, Markup, send_from_directory, send_file
  2. from flask_redis import FlaskRedis
  3. import json, abp
  4. app = Flask(__name__)
  5. redis = FlaskRedis(app)
  6. @app.route("/")
  7. def index():
  8. return render_template("index.html")
  9. @app.route("/graph", methods=["GET", "POST"])
  10. def graph(page):
  11. if request.method == 'POST':
  12. # Convert the data to a graph state
  13. g = abp.GraphState()
  14. g.from_json(json.loads(data))
  15. # Convert it back to JSON
  16. data = json.dumps(g.to_json(stringify=True))
  17. # Insert into the database
  18. redis.execute_command("SET", "graph", data)
  19. # Return success
  20. return "OK"
  21. else:
  22. # Get from the database
  23. return redis.get("graph")