Exemplo n.º 1
0
def __fetch_results(path, api_site_parameter, rpc = None, **url_params ):
    """
    Fetch results
    """
    
    params = {
        "site": api_site_parameter,
        "key": api_key,
        "pagesize": __default_page_size,
        "page": __default_page
        }
    
    #Inject the auth token if valorized 
    if not __debug:
        auth_token = TokenManager.get_auth_token()
        if auth_token:
            params['access_token'] = auth_token
    
    params.update(url_params)

    url = __build_url(path, api_site_parameter, **params)
    
    results = __gae_fetch(url, rpc = rpc)
    if rpc:
        pass
    else:
        return handle_response(results, url)
Exemplo n.º 2
0
def __fetch_results(path, api_site_parameter, rpc=None, **url_params):
    """
    Fetch results
    """

    #Backoff and respect the API
    if memcache.get('backoff') is not None:
        raise ApiRequestError(None, CODE_API_ERROR_THROTTLING,
                              API_ERROR_THROTTLING)

    params = {
        "site": api_site_parameter,
        "key": api_key,
        "pagesize": __default_page_size,
        "page": __default_page
    }

    #Inject the auth token if valorized
    if not __debug:
        auth_token = TokenManager.get_auth_token()
        if auth_token:
            params['access_token'] = auth_token

    params.update(url_params)

    url = __build_url(path, api_site_parameter, **params)

    results = __gae_fetch(url, rpc=rpc)
    if rpc:
        pass
    else:
        return handle_response(results, url)
Exemplo n.º 3
0
 def GET(self):
     result = {}
     action = web.input(action = None)['action']
     
     if action=='quota': 
         results = urlfetch.fetch('https://api.stackexchange.com/2.0/info?site=stackoverflow&key=%s' % api_key, headers = {'User-Agent': 'StackPrinter'}, deadline = 10)
         response = simplejson.loads(results.content)
         result['result'] = response
     if action=='quotaauth': 
         results = urlfetch.fetch('https://api.stackexchange.com/2.0/info?site=stackoverflow&key=%s&access_token=%s' % (api_key, TokenManager.get_auth_token()), headers = {'User-Agent': 'StackPrinter'}, deadline = 10)
         response = simplejson.loads(results.content)
         result['result'] = response
     if action=='authkey': 
         result['result'] = TokenManager.get_auth_token()
     elif action =='memcachestats':
         result = memcache.get_stats()        
     elif action =='memcacheflush':
         result['result'] = memcache.flush_all()
     elif action =='normalize':
         deferred.defer(worker.deferred_normalize_printed_question)    
         result['result'] = True
     elif action =='delete':
         service = web.input(service = None)['service']
         question_id = web.input(question_id = None)['question_id']
         result['printed_question_deletion'] = dbquestion.delete_printed_question(question_id,service)
         result['question_deletion'] = dbquestion.delete_question(question_id,service)
         result['answers_deletion'] = dbquestion.delete_answers(question_id,service)
     return render.admin(result)
Exemplo n.º 4
0
def __fetch_results(path, api_site_parameter, rpc = None, **url_params ):
    """
    Fetch results
    """
    
    #Backoff and respect the API
    if memcache.get('backoff') is not None:
        raise ApiRequestError(None, CODE_API_ERROR_THROTTLING, API_ERROR_THROTTLING)
    
    params = {
        "site": api_site_parameter,
        "key": api_key,
        "pagesize": __default_page_size,
        "page": __default_page
        }
    
    #Inject the auth token if valorized 
    if not __debug:
        auth_token = TokenManager.get_auth_token()
        if auth_token:
            params['access_token'] = auth_token
    
    params.update(url_params)

    url = __build_url(path, api_site_parameter, **params)
    
    results = __gae_fetch(url, rpc = rpc)
    if rpc:
        pass
    else:
        return handle_response(results, url)
Exemplo n.º 5
0
 def GET(self):
     result = {}
     action = web.input(action = None)['action']
     
     if action=='quota': 
         results = urlfetch.fetch('https://api.stackexchange.com/2.0/info?site=stackoverflow&key=%s' % api_key, headers = {'User-Agent': 'StackPrinter'}, deadline = 10)
         response = simplejson.loads(results.content)
         result['result'] = response
     if action=='quotaauth': 
         results = urlfetch.fetch('https://api.stackexchange.com/2.0/info?site=stackoverflow&key=%s&access_token=%s' % (api_key, TokenManager.get_auth_token()), headers = {'User-Agent': 'StackPrinter'}, deadline = 10)
         response = simplejson.loads(results.content)
         result['result'] = response
     if action=='authkey': 
         result['result'] = TokenManager.get_auth_token()
     elif action =='memcachestats':
         result = memcache.get_stats()        
     elif action =='memcacheflush':
         result['result'] = memcache.flush_all()
     elif action =='normalize':
         deferred.defer(worker.deferred_normalize_printed_question)    
         result['result'] = True
     elif action =='delete':
         service = web.input(service = None)['service']
         question_id = web.input(question_id = None)['question_id']
         result['printed_question_deletion'] = dbquestion.delete_printed_question(question_id,service)
         result['question_deletion'] = dbquestion.delete_question(question_id,service)
         result['answers_deletion'] = dbquestion.delete_answers(question_id,service)
     return render.admin(result)