[tor-commits] [compass/master] Built result.json request handler which returns JSON
karsten at torproject.org
karsten at torproject.org
Mon Jan 7 07:09:40 UTC 2013
commit 90febb91bddbb0522ee0d283b5ea2c0ee09aafe4
Author: Chris Wacek <cwacek at 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()
+ at 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():
More information about the tor-commits
mailing list