Przeglądaj źródła

Posting data works okay

master
Pete Shadbolt 7 lat temu
rodzic
commit
123917d641
2 zmienionych plików z 23 dodań i 4 usunięć
  1. +4
    -4
      app.py
  2. +19
    -0
      test.py

+ 4
- 4
app.py Wyświetl plik

@@ -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 Wyświetl plik

@@ -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


Ładowanie…
Anuluj
Zapisz