Browse Source

Posting data works okay

master
Pete Shadbolt 6 years ago
parent
commit
123917d641
2 changed files with 23 additions and 4 deletions
  1. +4
    -4
      app.py
  2. +19
    -0
      test.py

+ 4
- 4
app.py View File

@@ -10,20 +10,20 @@ def index():
return render_template("index.html")

@app.route("/graph", methods=["GET", "POST"])
def graph(page):
def graph():
if request.method == 'POST':
# Convert the data to a graph state
g = abp.GraphState()
g.from_json(json.loads(data))
g.from_json(json.loads(request.data))

# Convert it back to JSON
# Convert it back to JSON just for fun
data = json.dumps(g.to_json(stringify=True))

# Insert into the database
redis.execute_command("SET", "graph", data)

# Return success
return "OK"
return "Posted {} bytes OK".format(len(data))

else:
# Get from the database


+ 19
- 0
test.py View File

@@ -0,0 +1,19 @@
"""
Makes a dummy post to the test server
"""
import requests
import json
import abp

def test_graph():
N = 1000
g = abp.GraphState(range(N), vop="hadamard")
for i in range(N-1):
g.act_cz(i, i+1)
return g

if __name__ == '__main__':
data = json.dumps(test_graph().to_json())
r = requests.post("http://localhost:5000/graph", data=data)
print r.status_code, r.content


Loading…
Cancel
Save