commit 90febb91bddbb0522ee0d283b5ea2c0ee09aafe4 Author: Chris Wacek cwacek@cs.georgetown.edu Date: Thu Dec 20 16:32:18 2012 -0500
Built result.json request handler which returns JSON
Also uses the new selection functions which are a little bit saner. --- app.py | 20 +++++++++++++++++++- 1 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/app.py b/app.py index 159322d..95f63e6 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,8 @@ import os import re import compass -from util import Result,Boolean,NullFn,Int,Container +from util import Result,Boolean,NullFn,Int,Container,ResultEncoder +import json from flask import Flask, request, jsonify, render_template,Response
app = Flask(__name__) @@ -114,6 +115,23 @@ def parse(output_string, grouping=False, sort_key=None): def index(): return app.open_resource("templates/index.html").read()
+@app.route('/result.json', methods=['GET']) +def json_result(): + options = Opt(dict(request.args.items())) + + stats = compass.RelayStats(options) + results = stats.select_relays(stats.relays, + by_country=options.by_country, + by_as_number=options.by_as, + links=options.links) + + + relays = stats.sort_and_reduce(results, + options) + + return Response(json.dumps(relays, cls=ResultEncoder), mimetype='application/json') + +
@app.route('/result', methods=['GET']) def result():
tor-commits@lists.torproject.org