Commit 8109b619fa86e9c003f8e75554a636e0c1655580

  • avatar
  • Arvind <arvinkhadri @gm…l.com>
  • Wed May 29 19:08:15 IST 2013
Fixing issues and deprecating API
  - The application saves the data itself and then sweets it.
	- Adding /publish, this endpoint accepts stringified json and stores the content.
  
1212from urllib import quote_plus
1313from urllib import unquote_plus
1414import conf
15import sweetmaker
1516import oursql
1617import requests
1718from flask import jsonify
232232 response = jsonify(d)
233233 response.headers['Access-Control-Allow-Origin'] = '*'
234234 return response
235
235236@app.route('/blank', methods=['GET'])
236237def serve_blank():
237238 return render_template('blank.html')
357357 return response
358358
359359
360@app.route("/askSWeeT",methods=['POST'])
360@app.route('/publish', methods=['POST'])
361def publish():
362 print "entered"
363 data = json.loads(request.form['data'])
364 collection = g.db['post']
365 for i in data:
366 i['bxpath'] = ''
367 collection.insert(i)
368 sweet(data)
369 reply = make_response()
370 return reply
371
372
373def sweet(data):
374 """ A function to sweet the data that is inserted. Accepts a <list of dicts>. """
375 for i in data:
376 del(i['_id'])
377 sweet = sweetmaker.make(i['type'], i['author'], i['about'], i['data'])
378 sweetmaker.send(sweet)
379 return True
380 # data = json.dumps(data)
381 # req = requests.api.post(conf.SWEETURL[0]+"/add",{'data':data})
382 # if req.status_code == 200:
383 # reply = make_response()
384 # return reply
385
386
387@app.route("/askSWeeT", methods=['POST'])
361388def askSweet():
362389 data = json.loads(request.form['data'])
363390 for i in data:
  
1import requests
2import json
3import conf
4def make(what, who, where, how):
5 sweet = {}
6 sweet['what'] = what
7 sweet['who'] = who
8 sweet['where'] = where
9 sweet['how'] = how
10 print sweet
11 sweet_list = []
12 sweet_list.append(sweet)
13 return sweet_list
14
15
16def send(sweet):
17 request = requests.api.post(conf.SWEET_STORE_ADD[0],{'data':json.dumps(sweet)})
18 if request.status_code == 200:
19 return True
20 else:
21 return False
  
3636
3737 createMenu: function(type) {
3838 var xyz = '';
39 if(type === '1.0')
39 if(type === 're-narration')
4040 xyz = document.getElementById("show-box");
4141 else
4242 xyz = document.getElementById("show-comment");
4949 var para = document.createElement("p");
5050 var newel = document.createElement("a");
5151 newel.textContent = a11ypi.showbox[i]['lang'];
52 if(type === '1.0')
52 if(type === 're-narration')
5353 $(newel).attr("href",config.deploy+"/?foruri="+a['foruri']+"&lang="+a11ypi.showbox[i]['lang']+"&interactive=1"+"&type="+type);
5454 else
5555 $(newel).attr("href",config.deploy+"/?foruri="+a['foruri']+"&tags="+a11ypi.showbox[i]['lang']+"&interactive=0"+"&type="+type);
119119 if(a['type'])
120120 type = a['type'];
121121 else
122 type = '1.0'
122 type = 're-narration'
123123 var lang = '';
124124
125 if( type != '1.0')
125 if( type != 're-narration')
126126 lang = a['tags'];
127127 else
128128 lang = a['lang'];
152152 {
153153 console.log(e);
154154 }
155 if(a['type'] == '1.0')
155 if(a['type'] == 're-narration')
156156 {
157157 try{
158158 var result = nodes.iterateNext();
612612 d = window.location.search.split('?')[1];
613613 var a = a11ypi.getParams();
614614 if (a['blog'] === undefined ) {
615 a11ypi.createMenu('1.0');
615 a11ypi.createMenu('re-narration');
616616 }
617617 else {
618618 $('#show-box').attr('title', 'Choose a re-narration from the blog you specified.');
  
399399 });
400400 });
401401 });
402 $.post(config.sweet+'/add', {data : JSON.stringify(util.buildDataString())},
403 function(data){
404// data = JSON.parse(data);
405 $.post(config.deploy+'/askSWeeT',{'data':data},function(){
406 window.location.reload();
407 // console.log("success!!");
408 });
402 $.post(config.deploy+'/publish', {data : JSON.stringify(util.buildDataString())},
403 function(data){
404 window.location.reload();
405 });
409406
410 }); //+'&title='+encodeURIComponent(document.title)
407 //+'&title='+encodeURIComponent(document.title)
411408// }).done(function(){
412409 // console.log("test");
413410 //window.location.reload();
444444 var buff = [];
445445 util.forEach(util.history, function(index, command) {
446446 var dict = {};
447 dict['type'] = 1; //TYPE refers to the sweet type. The application says the type, 1 is re-narration.
447 dict['type'] = "re-narration"; //TYPE
448448 dict['about'] = decodeURIComponent(window.location.search.split('=')[1]);
449449 dict['lang'] = $('#lang-select').val();
450450 dict["location"] = $('#loc-select').val();