forked from data-mining-the-city/week-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
61 lines (43 loc) · 1.48 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from flask import Flask
from flask import render_template
import json
import time
import sys
import pyorient
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/getData/")
def getData():
client = pyorient.OrientDB("localhost", 2424)
session_id = client.connect("root", "password")
db_name = "property_test"
db_username = "admin"
db_password = "admin"
if client.db_exists( db_name, pyorient.STORAGE_TYPE_MEMORY ):
client.db_open( db_name, db_username, db_password )
print db_name + " opened successfully"
else:
print "database [" + db_name + "] does not exist! session ending..."
sys.exit()
lat1 = 22.532498
lat2 = 22.552317
lng1 = 114.044329
lng2 = 114.076644
query = 'SELECT FROM Listing WHERE latitude BETWEEN {} AND {} AND longitude BETWEEN {} AND {}'
records = client.command(query.format(lat1, lat2, lng1, lng2))
numListings = len(records)
print 'received ' + str(numListings) + ' records'
client.db_close()
output = {"type":"FeatureCollection","features":[]}
for record in records:
feature = {"type":"Feature","properties":{},"geometry":{"type":"Point"}}
feature["id"] = record._rid
feature["properties"]["name"] = record.title
feature["properties"]["price"] = record.price
feature["geometry"]["coordinates"] = [record.latitude, record.longitude]
output["features"].append(feature)
return json.dumps(output)
if __name__ == "__main__":
app.run(host='0.0.0.0',port=5000,debug=True,threaded=True)