| rev |
line source |
|
seanhalle@5
|
1 from bottle import route, run, template, response
|
|
seanhalle@5
|
2
|
|
seanhalle@5
|
3 graphFile = None
|
|
seanhalle@5
|
4
|
|
seanhalle@5
|
5 @route('/')
|
|
seanhalle@5
|
6 def index():
|
|
seanhalle@5
|
7 return '<b>Hello</b>!'
|
|
seanhalle@5
|
8
|
|
seanhalle@5
|
9 @route('/<name>')
|
|
seanhalle@5
|
10 @route('/hello/<name>')
|
|
seanhalle@5
|
11 def nameroute(name):
|
|
seanhalle@5
|
12 return template('<b>Hello {{name}}</b>!', name=name)
|
|
seanhalle@5
|
13
|
|
seanhalle@5
|
14 @route('/savejson/<thejson>')
|
|
seanhalle@5
|
15 def savejson(thejson):
|
|
seanhalle@5
|
16 text_file = open("syntaxGraph.json", "w")
|
|
seanhalle@5
|
17 text_file.write("%s" % thejson)
|
|
seanhalle@5
|
18 text_file.close()
|
|
seanhalle@5
|
19 print "hello"
|
|
seanhalle@5
|
20 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
21 # return 'Got JSON!'
|
|
seanhalle@5
|
22 # return template('Got JSON! {{printjson}}</b>!', printjson = thejson)
|
|
seanhalle@5
|
23
|
|
seanhalle@5
|
24 @route('/getjson')
|
|
seanhalle@5
|
25 def getjson():
|
|
seanhalle@5
|
26 text_file = open("syntaxGraph.json", "r")
|
|
seanhalle@5
|
27 returnjson = text_file.read()
|
|
seanhalle@5
|
28 text_file.close()
|
|
seanhalle@5
|
29 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
30 return returnjson
|
|
seanhalle@5
|
31
|
|
seanhalle@5
|
32 #===============
|
|
seanhalle@5
|
33 @route('/startsavinggraph')
|
|
seanhalle@5
|
34 def startsavinggraph():
|
|
seanhalle@5
|
35 global graphFile
|
|
seanhalle@5
|
36 graphFile = open("syntaxGraph.json", "w")
|
|
seanhalle@5
|
37 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
38
|
|
seanhalle@5
|
39 @route('/save1elem/<thejson>')
|
|
seanhalle@5
|
40 def save1elem(thejson):
|
|
seanhalle@5
|
41 global graphFile
|
|
seanhalle@5
|
42 graphFile.write("%s\n" % thejson)
|
|
seanhalle@5
|
43 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
44
|
|
seanhalle@5
|
45 @route('/endsavinggraph')
|
|
seanhalle@5
|
46 def endsavinggraph():
|
|
seanhalle@5
|
47 global graphFile
|
|
seanhalle@5
|
48 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
49 graphFile.close()
|
|
seanhalle@5
|
50
|
|
seanhalle@5
|
51 #================
|
|
seanhalle@5
|
52
|
|
seanhalle@5
|
53 @route('/startretrievinggraph')
|
|
seanhalle@5
|
54 def startretrievinggraph():
|
|
seanhalle@5
|
55 global graphFile
|
|
seanhalle@5
|
56 graphFile = open("syntaxGraph.json", "r")
|
|
seanhalle@5
|
57 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
58
|
|
seanhalle@5
|
59 @route('/get1elem')
|
|
seanhalle@5
|
60 def get1elem():
|
|
seanhalle@5
|
61 global graphFile
|
|
seanhalle@5
|
62 returnjson = graphFile.readline()
|
|
seanhalle@5
|
63 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
64 return returnjson
|
|
seanhalle@5
|
65
|
|
seanhalle@5
|
66 @route('/endretrievinggraph')
|
|
seanhalle@5
|
67 def endretrievinggraph():
|
|
seanhalle@5
|
68 global graphFile
|
|
seanhalle@5
|
69 response.set_header('Access-Control-Allow-Origin', '*')
|
|
seanhalle@5
|
70 graphFile.close()
|
|
seanhalle@5
|
71
|
|
seanhalle@5
|
72 run(host='localhost', port=8080)
|