Esempio n. 1
0
 def _apicall(self, method, **params):
     params['login'] = self.username
     params['apiKey'] = self.api_key
     params['version'] = '2.0.1'
     params['format'] = 'json'
     url = BASE_URL + method + '?' + urllib.urlencode(params)
     return utils.getjson(url)
Esempio n. 2
0
 def render(self, context):
     base_url = 'http://ajax.googleapis.com/ajax/services/search/news?'
     query = self.query.resolve(context)
     params = {
         'v': '1.0',
         'rsz': 'large', # get 8 results
         'q': query
     }
     if hasattr(settings, "GOOGLE_API_KEY"):
         params['key'] = settings.GOOGLE_API_KEY
     
     url = base_url + urllib.urlencode(params)
     response = utils.getjson(url)
     try:
         results = response['responseData']['results']
     except: # sometimes, weird responses come back that just break
         results = ''
     
     if self.var_name:
         context[self.var_name] = results
         return ''
     
     return results