Simulate graph states in the browser
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

33 lignes
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")