def get(self): func = None action = self.request.get('action') if action: if action[0] == '_': self.error(403) # access denied return else: func = getattr(self.methods, action, None) if not func: self.error(404) # file not found return args = () while True: key = 'arg%d' % len(args) val = self.request.get(key) if val: args += (simplejson.loads(val),) else: break result = func(*args) if self.request.get('callback'): self.response.out.write(self.request.get("callback") + "(" + str(simplejson.dumps(result)).replace("\n", "") + ");") else: self.response.out.write(simplejson.dumps(result))
def get(self): logging.info('Loading Login Response') token = self.request.get('token') url = 'https://rpxnow.com/api/v2/auth_info' args = { 'format': 'json', 'apiKey': RPX_API_KEY, 'token': token } r = urlfetch.fetch(url=url, payload=urllib.urlencode(args), method=urlfetch.POST, headers={'Content-Type':'application/x-www-form-urlencoded'} ) json = simplejson.loads(r.content) if self.validate_response(json): if self.session['reset_account']: from accounts.methods import reset_account self.session['user'] = reset_account(self.session['reset_account'], json['profile']['identifier']) self.session['reset_account'] = False else: self.session['user'] = registered(json['profile']['identifier']) # check to see if this_user is registered if self.session['user'] is False: return self.register_user(json) else: if not self.session['continue']: self.session['continue'] = '/profile/' + self.session['user'].profile_path self.redirect(self.session['continue']) self.session['continue'] = False return
def refresh_scores(self, verbose): scores = [] json_file = open(ROOT_PATH + "/data/item_scores.json") json_str = json_file.read() newdata = simplejson.loads(json_str) # Load JSON file as object # Retrieve Proficiency. If new, then save it. for item in newdata: # Store Item in Datastore if item["type"] == "trash": continue if item["type"] == "temp": continue this_taker = QuizTaker.get(item["quiz_taker"]["key"]) this_vendor = Employer.get(item["vendor"]["key"]) this_item = QuizItem.get(item["quiz_item"]["key"]) score = ItemScore( quiz_taker=this_taker, picked_answer=item["picked_answer"], correct_answer=item["correct_answer"], score=item["score"], quiz_item=this_item, vendor=this_vendor, type=item["type"], ) # Add List of Answers scores.append(score) if verbose[0] == "loud": print encode(score) db.put(scores) # save scores
def trim(self): self.request_args = { 'url': self.url } self.formatted_args = urllib.urlencode(self.request_args) from google.appengine.api import urlfetch fetch_page = urlfetch.fetch(url = TRIM_URL + self.formatted_args, method = urlfetch.GET) response = simplejson.loads(fetch_page.content) # um, this is a bad idea in real life return response['url'].replace('\\/','\\' )
def load_json(self, data_type, path): logging.info('loading json for data type %s', data_type) json_file = open(ROOT_PATH + "/data/" + path + str(data_type) + ".json") json_str = json_file.read() json_data = simplejson.loads(json_str) # Load JSON file as object memcache.set("json_" + str(data_type), json_data, 60000) entities = [] # Setup, Imports if data_type == 'employers': emp = emp_data()
def bitly(self): self.request_args = {'version': '2.0.1', 'login': BITLY_LOGIN, 'apiKey': BITLY_API_KEY, 'longUrl': self.url } self.formatted_args = urllib.urlencode(self.request_args) from google.appengine.api import urlfetch fetch_page = urlfetch.fetch(url = BITLY_URL + self.formatted_args, method = urlfetch.GET) response = simplejson.loads(fetch_page.content) # um, this is a bad idea in real life return response['results'][self.url]['shortUrl']
def post(self): args = simplejson.loads(self.request.body) func, args = args[0], args[1:] if func[0] == '_': self.error(403) # access denied return func = getattr(self.methods, func, None) if not func: self.error(404) # file not found return result = func(*args) self.response.out.write(simplejson.dumps(result))
def get(self): print "" json_file = open(ROOT_PATH + "/data/topics.json") json_str = json_file.read() from utils import simplejson newdata = simplejson.loads(json_str) # Load JSON file as object topics = [] types = [] for t in newdata: topics.append(t) print t['name'] return template_values = {} path = tpl_path(DEV_PATH +'admin.html') self.response.out.write(template.render(path, template_values))
def request(): args = {'method': 'zemanta.suggest', 'api_key': API_KEY, 'text': '''The Phoenix Mars Lander has successfully deployed its robotic arm and tested other instruments including a laser designed to detect dust, clouds, and fog. The arm will be used to dig up samples of the Martian surface which will be analyzed as a possible habitat for life.''', 'return_categories': 'dmoz', 'format': 'json'} print "" print "Request text is:", args['text'] args_enc = urllib.urlencode(args) fetch_page = urlfetch.fetch(GATEWAY, payload=args_enc, method="POST") output = simplejson.loads(fetch_page.content) print "" print "" for cat in output['categories']: print "this text is classified in the category: ", cat['name'], "with confidence: ", cat['confidence'] print "" print "" for key in output['keywords']: print "this text has keywords category: ", key['name'], "with confidence: ", key['confidence'] print "" print output