Commit ec31827a7fcc3cb713de0c073d778d74ca9c51be
- Diff rendering mode:
- inline
- side by side
server/alipi.py
(19 / 34)
  | |||
17 | 17 | @app.before_request | |
18 | 18 | def first(): | |
19 | 19 | g.connection = pymongo.Connection('localhost',27017) #Create the object once and use it. | |
20 | g.db = g.connection['dev_alipi'] | ||
20 | g.db = g.connection[conf.MONGODB[0]] | ||
21 | 21 | @app.teardown_request | |
22 | 22 | def close(exception): | |
23 | 23 | g.connection.disconnect() | |
… | … | ||
286 | 286 | response = jsonify(d) | |
287 | 287 | response.headers['Access-Control-Allow-Origin'] = '*' | |
288 | 288 | return response | |
289 | |||
290 | # string='' | ||
291 | # if len(query)==0: | ||
292 | # print >> environ['wsgi.errors'], 'empty' | ||
293 | # return 'empty' | ||
294 | # else: | ||
295 | # for key in query: | ||
296 | # # print >> environ['wsgi.errors'], query | ||
297 | # post = key['narration'][len(key['narration'])-1] #Fetching the last done re-narration | ||
298 | |||
299 | # try: | ||
300 | # string+="###" | ||
301 | 289 | ||
302 | # for key in post: | ||
303 | # if type(post[key]) is not float: | ||
304 | # if key != '_id': | ||
305 | # try: | ||
306 | # if type(post[key]) is unicode: | ||
307 | # string+="&"+str(key)+"::"+ post[key].encode('utf-8') | ||
308 | # else: | ||
309 | # string+="&"+str(key)+"::"+ post[key] | ||
310 | # except TypeError: | ||
311 | # print >> environ['wsgi.errors'], key | ||
312 | # else: | ||
313 | # try: | ||
314 | # string+="&"+str(key)+"::"+ str(post[key]) | ||
315 | # except TypeError: | ||
316 | # print >> environ['wsgi.errors'], key | ||
317 | # except UnicodeEncodeError: | ||
318 | # print >> environ['wsgi.errors'], key | ||
319 | # print >> environ['wsgi.errors'], 'Error Encoding request string' | ||
320 | # return 'empty' | ||
321 | |||
322 | # return string | ||
290 | @app.route('/feeds', methods=['GET']) | ||
291 | def serve_feed_temp(): | ||
292 | return render_template("feeds.html") | ||
293 | |||
294 | @app.route('/feed', methods=['GET']) | ||
295 | def serve_feed(): | ||
296 | coll = g.db['post'] | ||
297 | d = {} | ||
298 | cntr = 0 | ||
299 | for i in coll.find(): | ||
300 | if i['data'] != '<br/>': | ||
301 | i['_id'] = str(i['_id']) | ||
302 | d[cntr] = i | ||
303 | cntr+=1 | ||
304 | response = jsonify(d) | ||
305 | response.headers['Access-Control-Allow-Origin'] = '*' | ||
306 | return response | ||
307 | |||
323 | 308 | ||
324 | 309 | import logging,os | |
325 | 310 | from logging import FileHandler |
server/templates/feeds.html
(21 / 0)
  | |||
1 | <!doctype html> | ||
2 | <head> | ||
3 | <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> | ||
4 | <script type="text/javascript"> | ||
5 | $.getJSON("http://127.0.0.1:5000/feed", function(data) | ||
6 | { | ||
7 | str = ""; | ||
8 | $.each(data, function(i, val) | ||
9 | { | ||
10 | if(val['about'] != undefined && val['about'] != 'undefined' && val['author'] != 'undefined' ) | ||
11 | str += "<p>\n<b>@" +val['author']+"</b> has narrated <b>"+val['about']+"#"+val['xpath']+"</b> at <b>"+val['blog']+"#"+val['bxpath']+"</b> for <b>"+val['location']+"</b> in <b>"+val['lang']+"</b>\n</p>"; | ||
12 | }); | ||
13 | $("#feeds").html(str); | ||
14 | }); | ||
15 | </script> | ||
16 | </head> | ||
17 | <body style="text-wrap:normal"> | ||
18 | <div id="feeds"> | ||
19 | </div> | ||
20 | </body> | ||
21 | </html> |