Пример #1
0
  def get(self):
    response = fetch( \
      "https://rpxnow.com/api/v2/auth_info",
      payload = "apiKey=%s&token=%s" % \
    (
      "c53e2281f9009394b91c66e3a1914209b69cb4cd",
      self.request.get('token')
        ),
      method = POST
    )
    obj = parse_json(response.content)
    if response.status_code != 200 or obj['stat'] == 'fail':
      self.response.out.write("Fail! " + response.content)
      return


    if self.user:
      if 'identifier' in obj['profile']:
        user = User.all().filter('identifier', obj['profile']['identifier']).get()
	if user:
          self.render_error('already_exists', {'user' : user })
	  return
      self.user.verified = True
      self.user.update_from_profile(obj['profile'])
    else:
      self.user = User.from_profile(obj['profile'])

    self.generate_authenticity_token()
      
    self.redirect('/')
Пример #2
0
 def _get_source(self, url):
     try:
         page = urllib2.urlopen(url)
         source = parse_json(page.read())
         page.close()
     except:
         return None
     return source["responseData"]
Пример #3
0
 def _get_source(self):
     url = self._url
     try:
         page = urllib2.urlopen(url)
         source = parse_json(page.read())
         page.close()
     except:
         return None
     return source
Пример #4
0
 def moderate_post(self, forum_key, post_id, action):
     url = 'http://disqus.com/api/moderate_post/'
     key = self._key
     payload = {'forum_api_key':forum_key,
                'user_api_key':key,
                'post_id':post_id,
                'action':action} 
     payload = urllib.urlencode(payload)
     result = urlfetch.fetch(url, payload=payload, method='POST').content
     json = parse_json(result)
     if 'ok' != json['code']:
         logging.info(json['code'])
         return {'succeeded': False}
     return json
Пример #5
0
 def parse_data(self, data):
     if not data:
         return None
     json = parse_json(data)
     try:
         code = json['code']
         messages = json['message']
     except:
         return None
     if 'ok' != code:
         logging.info('parse data failed')
         return None
     datalist = []
     for message in messages:
         avatar = 'http://www.gravatar.com/avatar/'
         username = '******'
         email = '*****@*****.**'
         if message['is_anonymous']:
             avatar += message['anonymous_author']['email_hash']
             avatar += '?size=48'
             username = message['anonymous_author']['name']
             email = message['anonymous_author']['email']
         else:
             if message['author']['has_avatar']:
                 avatar = message['author']['avatar']['medium']
             else:
                 avatar += message['author']['email_hash']
                 avatar += '?size=48'
             username = message['author']['display_name'] or message['author']['username']
             email = message['author']['email']
         rdic = {}
         rdic['avatar'] = avatar
         rdic['username'] = username
         rdic['email'] = email
         rdic['ip'] = message['ip_address']
         rdic['comment_id'] = message['id']
         rdic['content'] = message['message']
         rdic['status'] = message['status']
         rdic['created'] = message['created_at']
         rdic['moderated'] = message['has_been_moderated']
         rdic['thread'] = message['thread']
         datalist.append(rdic)
     return datalist
Пример #6
0
        GSEARCH_URL = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=filtered_cse&q=%(q)s&start=%(start)s'
    try:
        q = quote(q.encode('utf-8'))
    except:
        q = quote(q)
    gdic = dict(cx=cx,q=q,start=start)
    url = GSEARCH_URL % gdic
    try:
        res = urlfetch.fetch(url)
    except urlfetch.DownloadError, e:
        logging.error('Search Download Error: ' + str(e))
        raise urlfetch.DownloadError
    if 200 != res.status_code:
        logging.error('Search Status Error: ' + str(res.status_code))
        raise Exception('Search Status Error: ' + str(res.status_code))
    gres = parse_json(res.content)
    if 200 != gres['responseStatus']:
        logging.error('Search responseStatus Error: ' + str(gres['responseDetails']))
        raise Exception('Search responseStatus Error: ' + str(gres['responseDetails']))
    return gres['responseData']

apps = webapp.WSGIApplication(
    [
        ('/', Index),
        ('/search', Search),
        ('/archive', Archive),
        ('/a/(.*)', Article),
        ('/k/(.*)', Keyword),
        ('/p/(.*)', Page),
        ('/d/(.*)', DEMO),
        ('/feed', Atom),