JSON output in Bottle, Python and MongoDB -


i running bottle , python pull data mongodb. output comes in json object format.
used have following

{u'product': u'mortgage', u'total_product': 146533} {u'product': u'debt collection', u'total_product': 65639} 

but wanted rid of 'u , following format:

'product':'mortgage', total_product: 146533 'product':'debt collection' 'total_product:65639 

after running code, left blank screen no results , no error message. suggestion?

# find single  aggregates  choices = dict(     aggr1 = db.complaints.aggregate([{"$group":{"_id":"$disputed", "total_disputed":{"$sum":1}}},{"$sort":{"total_disputed":-1}},{"$project":{"_id":0, "disputed":"$_id", "total_disputed":1}}]),     aggr2 = db.complaints.aggregate([{"$group":{"_id":"$product", "total_product":{"$sum":1}}},{"$sort":{"total_product":-1}},{"$project":{"_id":0, "product":"$_id", "total_product":1}}]),     aggr3 = db.complaints.aggregate([{"$group":{"_id":"$response", "total_response":{"$sum":1}}},{"$sort":{"total_response":-1}},{"$project":{"_id":0, "response":"$_id", "total_response":1}}]),     aggr4 = db.complaints.aggregate([{"$group":{"_id":"$submitted", "total_submitted":{"$sum":1}}},{"$sort":{"total_submitted":-1}},{"$project":{"_id":0, "submitted":"$_id", "total_submitted":1}}]),     aggr5 = db.complaints.aggregate([{"$group":{"_id":"$timely", "total_timely":{"$sum":1}}},{"$sort":{"total_timely":-1}},{"$project":{"_id":0, "timely":"$_id", "total_timely":1}}]) )  def convert_keys_to_string(choices):     """recursively converts dictionary keys strings."""     if not isinstance(choices, dict):         return choices     return dict((str(k), convert_keys_to_string(v))          k, v in dictionary.items()) aggr1 = 'aggr1' aggr2 = 'aggr2' aggr3 = 'aggr3' aggr4 = 'aggr4' aggr5 = 'aggr5'       return bottle.template('analytics.tpl',  things1 = choices[aggr1], things2 = choices[aggr2], things3 = choices[aggr3], things4 = choices[aggr4], things5 = choices[aggr5])  bottle.debug(true) bottle.run(host='localhost', port=8082) 

the tpl follows:

<!doctype html> <html> <head> <title> @2015 </title> </head> <body> <p>  </p> <p> <ul> %for thing1 in things1: <li>{{thing1}}</li> %end </ul></p> <p> <ul> %for thing2 in things2: <li>{{thing2}}</li> %end </ul></p>    </body> </html> 

kindest regards

you using convertion string of dict in template {{thing1}}.

just write template, format dict-entries want:

%for thing1 in things1: <li>'product':'{thing1.product}', total_product: {{thing1.total_product}}</li> %end 

or

%for thing1 in things1: <li>'product':'{thing1.product}' 'total_product:{{thing1.total_product}}</li> %end 

your question not clear, 1 prefer.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -