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
862B

  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():
  11. if request.method == 'POST':
  12. # Convert the data to a graph state
  13. g = abp.GraphState()
  14. g.from_json(json.loads(request.data))
  15. # Convert it back to JSON just for fun
  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 "Posted {} bytes OK".format(len(data))
  21. else:
  22. # Get from the database
  23. return redis.get("graph")