diff --git a/app.py b/app.py index bdf9eda..956c8a4 100644 --- a/app.py +++ b/app.py @@ -1,24 +1,53 @@ from flask import Flask from flask import render_template +from flask import request +from flask import Response import json import time import sys +import random import pyorient +from Queue import Queue + app = Flask(__name__) +q = Queue() + +def event_stream(): + while True: + result = q.get() + yield 'data: %s\n\n' % str(result) + +@app.route('/eventSource/') +def sse_source(): + return Response( + event_stream(), + mimetype='text/event-stream') + @app.route("/") def index(): return render_template("index.html") @app.route("/getData/") def getData(): + + # TRY TO SEND BACK OTHER MESSAGES FROM THE SERVER. + # MAKE SURE THE MESSAGES ARE BEING DISPLAYED ON THE FRONT END. + q.put("starting data query...") + + lat1 = str(request.args.get('lat1')) + lng1 = str(request.args.get('lng1')) + lat2 = str(request.args.get('lat2')) + lng2 = str(request.args.get('lng2')) + + print "received coordinates: [" + lat1 + ", " + lat2 + "], [" + lng1 + ", " + lng2 + "]" client = pyorient.OrientDB("localhost", 2424) - session_id = client.connect("root", "password") - db_name = "property_test" + session_id = client.connect("root", "R0n+H3rm10n3") + db_name = "soufun2" db_username = "admin" db_password = "admin" @@ -28,17 +57,14 @@ def getData(): 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)) + random.shuffle(records) + records = records[:100] + numListings = len(records) print 'received ' + str(numListings) + ' records' @@ -55,7 +81,9 @@ def getData(): output["features"].append(feature) + q.put('idle') + return json.dumps(output) if __name__ == "__main__": - app.run(host='0.0.0.0',port=5000,debug=True,threaded=True) \ No newline at end of file + app.run(host='0.0.0.0',port=5001,debug=True,threaded=True) \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 504b7cd..262a989 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,6 +1,6 @@ - Flask Demo + DMC Web Stack @@ -9,15 +9,54 @@ body { padding: 0; margin: 0; + font-family: Helvetica, Arial, sans-serif; + font-size: 12px; + line-height: 18px; } html, body, #map { height: 100%; } + /*EXPERIMENT WITH DIFFERENT STYLING FOR THE CIRCLES AND WHAT HAPPENS WHEN THE MOUSE HOVERS OVER THEM*/ circle { - fill-opacity: 0; - stroke: red; - stroke-width: 5px; + fill-opacity: 10; + fill: yellow; + stroke-width: .3px; + } + circle:hover { + stroke: white; + stroke-width: 2px + stroke-opacity: 50; + cursor: crosshair; + } + + /*EXPERIMENT WITH YOUR OWN STYLING RULES TO CHANGE THE APPEARANCE OF THE TOOLTIP, THE MENU, AND THE MESSAGE TEXT*/ + div.tooltip{ + padding: 6px; + background: white; + visibility: hidden; + position: absolute; + z-index: 10; + } + p.tooltip-text{ + margin: 0px; + padding: 0px; + } + + div.menu{ + position: fixed; + margin: 0px; + padding: 10px; + top: 0px; + right: 0px; + width: 250px; + height: 500px; + background: rgba(255,255,255,.8); + } + + em{ + color: red; + font-weight: bold; } @@ -28,8 +67,39 @@
+ +
+

This is the title

+

This is the price

+
+ + + + +