Browse Source

Now we are getting somewhere with the server

master
Pete Shadbolt 8 years ago
parent
commit
54d7657374
2 changed files with 36 additions and 7 deletions
  1. +10
    -3
      examples/client.py
  2. +26
    -4
      server/server.py

+ 10
- 3
examples/client.py View File

@@ -2,7 +2,14 @@ import requests
import abp, json

s = requests.Session()
output = json.loads(s.get("http://localhost:5000/state").content)
print output
state = json.loads(s.post("http://localhost:5000/state").content)
output = s.get("http://localhost:5000/state").content
s.post("http://localhost:5000/state", output).content

s.get("http://localhost:5000/add/99")
s.get("http://localhost:5000/add/100")

print s.get("http://localhost:5000/state").content

s.get("http://localhost:5000/clear")
s.close()


+ 26
- 4
server/server.py View File

@@ -1,4 +1,5 @@
from flask import Flask, request, render_template, jsonify
import json
import abp

graphstate = abp.GraphState()
@@ -8,18 +9,39 @@ app = Flask(__name__)
def index():
return render_template("index.html")

@app.route("/state")
@app.route("/state", methods = ["GET", "POST"])
def state():
if request.method == "GET":
return jsonify(graphstate.to_json())
elif request.method == "POST":
graphstate.from_json(request.data)
graphstate.from_json(json.loads(request.data))
return jsonify(graphstate.to_json())

@app.route("/state")
def state():
@app.route("/add/<int:node>")
def add(node):
""" Add a node to the graph """
graphstate.add_node(node)
return jsonify(graphstate.to_json())

@app.route("/rotate/<int:node>/<int:operation>")
def rotate(node):
""" Add a node to the graph """
graphstate.act_local_rotation(node, operation)
return jsonify(graphstate.to_json())

@app.route("/cz/<int:a>/<int:b>")
def cz(a, b):
""" Add a node to the graph """
graphstate.act_cz(a, b)
return jsonify(graphstate.to_json())

@app.route("/clear")
def clear():
""" Clear the current state """
graphstate = abp.GraphState()
return jsonify({"clear": "ok"})

if __name__ == "__main__":
app.debug = True
app.run(host="0.0.0.0")


Loading…
Cancel
Save