def submit(): c = pymongo.Connection() db = c['mural'] coll = db['data'] requestData = json.loads(request.form['data']) try: for i in requestData: coll.insert(i) print 'inserted' print requestData response = make_response() response.headers['Access-Control-Allow-Origin'] = '*' response.status_code = 200 for i in requestData: del(i['_id']) i['how'] = '{concepts: ' + ', '.join(i['how']) + '}' #i['how'] = attribs print 'payload for sweet' print requestData sweetmaker.sweet(SWEET_STORE_URL, requestData) except: response = make_response() response.status_code = 500 response.data = "Your post could not be saved. Try posting again." return response
def sweet(data): """ A function to sweet the data that is inserted. Accepts a <list of dicts>. """ for i in data: print i if 'type' in i: del (i['_id']) sweetmaker.sweet( conf.SWEET_STORE_ADD[0] + "?access_token=" + session['auth_tok']['access_token'], [{ "what": i['type'], "who": session['username'], "where": i['about'], "how": { 'blogUrl': '{0}/#{1}'.format( conf.CUSTOM_BLOG_URL[0], g.response_from_blogger.json()['name']), 'language': i['lang'], 'location': i['location'], 'xpath': i['xpath'] } }]) return True
def sweet(data): """ A function to sweet the data that is inserted. Accepts a <list of dicts>. """ for i in data: if 'type' in i: del(i['_id']) sweetmaker.sweet(conf.SWEET_STORE_ADD[0], [{"what":i['type'], "who":i['author'], "where":i['about']+i['xpath'], "how":conf.CUSTOM_BLOG_URL[0]+"/#"+g.response_from_blogger.json()['name']+' {lang: '+i["lang"]+',loc: '+i["location"]+'}'}]) return True
def sweet(data): """ A function to sweet the data that is inserted. Accepts a <list of dicts>. """ for i in data: print i if 'type' in i: del(i['_id']) sweetmaker.sweet(conf.SWEET_STORE_ADD[0] + "?access_token=" + session['auth_tok'] ['access_token'], [{"what": i['type'], "who": session['username'], "where":i['about'], "how":{'blogUrl': '{0}/#{1}'.format( conf.CUSTOM_BLOG_URL[0], g.response_from_blogger.json()['name']), 'language': i['lang'], 'location': i['location'], 'xpath': i['xpath']}}]) return True
def publish(): connection = pymongo.Connection() db = connection['sml'] collection = db['data'] data = {} data = request.get_json(force=True) try: collection.insert(data) print 'inserted' response = make_response() response.headers['Access-Control-Allow-Origin'] = '*' response.status_code = 200 del (data['_id']) print data sweetmaker.sweet(data) except: response = make_response() response.satus_code = 500 response.data = "Your post could not be saved. Try posting again" return ""