Commit e9a1c9545d8c1f731d00646ddc335f0dbd2a2caa

  • avatar
  • arvind
  • Wed May 01 12:40:24 IST 2013
Cleaning up API-
  /askSWeeT gets a list of id for which it should contact the SWeeT server.
	pageEditor.js sends a list of id to /askSWeeT
  
1414import conf
1515import oursql
1616import requests
17
1817from flask import jsonify
18import json
19
20
1921app = Flask(__name__)
2022@app.before_request
2123def first():
357357
358358@app.route("/askSWeeT",methods=['POST'])
359359def askSweet():
360 id = request.form['id']
361 response = requests.api.get(conf.SWEETURL[0]"/query/"+id)
362 collection = g.db['post']
363 if response.status_code == 200:
364 collection.insert(response.json)
365 reply = make_response()
366 return reply
360 data = json.loads(request.form['data'])
361 for i in data:
362 response = requests.api.get(conf.SWEETURL[0]+"/query/"+i['id'])
363 collection = g.db['post']
364 rep = response.json()
365 rep['bxpath'] = ''
366 if response.status_code == 200:
367 collection.insert(rep)
368 reply = make_response()
369 return reply
367370
368371@app.route("/menu",methods=['GET'])
369372def menuForDialog():
  
401401 });
402402 $.post(config.sweet+'/add', {data : JSON.stringify(util.buildDataString())},
403403 function(data){
404 data = JSON.parse(data);
405 for(var i in data){
406 $.post(config.deploy+'/askSWeeT',{'id':data[i]['id']},function(){
407 console.log("success!!");});
408 }
404// data = JSON.parse(data);
405 $.post(config.deploy+'/askSWeeT',{'data':data},function(){
406 console.log("success!!");});
407
409408 }); //+'&title='+encodeURIComponent(document.title)
410409// }).done(function(){
411410 // console.log("test");