-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
43 lines (33 loc) · 1.31 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask, request,render_template, jsonify
from arango import ArangoClient
app = Flask(__name__)
# Replace with your ArangoDB connection details
client = ArangoClient(hosts=["https://YourArangoAppIp:Port"])
# Login with username and password (replace with your credentials)
db = client.db("databasename",username="root", password="password") #use the root password given at the deployment overview page
@app.route('/', methods = ['GET'])
def index():
return render_template('graph.html')
# Define the AQL query
@app.route('/Search', methods = ['GET'])
def Search():
place1 = "places/" + request.args.get('place1')
place2 = "places/" + request.args.get('place2')
query = """
FOR vertex, edge
IN OUTBOUND SHORTEST_PATH @place1 TO @place2
GRAPH 'kShortestPathsGraph'
OPTIONS {weightAttribute: 'travelTime'}
return {vertex, edge}
"""
bind_vars = {
'place1': place1,
'place2': place2
}
# Execute the query on the database
cursor = db.aql.execute(query, bind_vars=bind_vars)
data = [document for document in cursor]
return jsonify(data)
# # Get the shortest path as a list of vertex keys
if __name__ == "__main__":
app.run(debug=True)