Exemple #1
0
 def download(self, path, sheet_id, sheet_gid):
   credentials = self._get_credentials()
   http = httplib2.Http(ca_certs=utils.get_cacerts_path())
   http = credentials.authorize(http)
   service = discovery.build('drive', 'v2', http=http)
   resp = service.files().get(fileId=sheet_id).execute()
   ext = os.path.splitext(self.config.path)[1]
   convert_to = None
   if ext == '.json':
     ext = '.csv'
     convert_to = '.json'
   for mimetype, url in resp['exportLinks'].iteritems():
     if not mimetype.endswith(ext[1:]):
       continue
     if self.config.gid:
       url += '&gid={}'.format(self.config.gid)
     resp, content = service._http.request(url)
     if resp.status != 200:
       self.logger.error('Error downloading Google Sheet: {}'.format(path))
       break
     if convert_to == '.json':
       fp = cStringIO.StringIO()
       fp.write(content)
       fp.seek(0)
       reader = csv.DictReader(fp)
       content = json.dumps([row for row in reader])
     self.pod.write_file(path, content)
     self.logger.info('Downloaded Google Sheet -> {}'.format(path))
Exemple #2
0
 def create_service(authenticated=True):
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     if authenticated:
         credentials = oauth.get_or_create_credentials(
             scope=OAUTH_SCOPE, storage_key='Grow SDK')
         http = credentials.authorize(http)
     key = None if authenticated else oauth.BROWSER_API_KEY
     return discovery.build('blogger', 'v3', http=http, developerKey=key)
Exemple #3
0
 def create_service(authenticated=True):
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     if authenticated:
         credentials = oauth.get_or_create_credentials(
             scope=OAUTH_SCOPE, storage_key='Grow SDK')
         http = credentials.authorize(http)
     key = None if authenticated else oauth.BROWSER_API_KEY
     return discovery.build('blogger', 'v3', http=http, developerKey=key)
Exemple #4
0
def _get_parser():
    global _parser
    if _parser is None:
        credentials = oauth.get_or_create_credentials(
            scope=SCOPES, storage_key=STORAGE_KEY)
        http = httplib2.Http(ca_certs=utils.get_cacerts_path())
        http = credentials.authorize(http)
        service = discovery.build('language', 'v1beta2', http=http)
        _parser = budou.get_parser('nlapi', service=service)
    return _parser
 def bucket(self):
   if self.use_interoperable_auth:
     gs_connection = boto.connect_gs(
         self.config.access_key, self.config.access_secret,
         calling_format=connection.OrdinaryCallingFormat())
     # Always use our internal cacerts.txt file. This fixes an issue with the
     # PyInstaller-based frozen distribution, while allowing us to continue to
     # verify certificates and use a secure connection.
     gs_connection.ca_certificates_file = utils.get_cacerts_path()
   else:
     gs_connection = storage.get_connection(
         self.config.project, self.config.email, self.config.key_path)
   return gs_connection.get_bucket(self.config.bucket)
Exemple #6
0
 def create_service(host):
     credentials = oauth.get_or_create_credentials(
         scope=OAUTH_SCOPES, storage_key=STORAGE_KEY)
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     http = credentials.authorize(http)
     # Kintaro's server doesn't seem to be able to refresh expired tokens
     # properly (responds with a "Stateless token expired" error).  So for
     # now, automatically refresh tokens each time a service is created. If
     # this isn't fixed on the Kintaro end, what we can do is implement our
     # own refresh system (tokens need to be refreshed once per hour).
     credentials.refresh(http)
     url = DISCOVERY_URL.replace('{host}', host)
     return discovery.build('content', 'v1', http=http,
                            discoveryServiceUrl=url)
Exemple #7
0
 def bucket(self):
     if self.config.oauth2:
         enable_oauth2_auth_handler()
     gs_connection = boto.connect_gs(
         self.config.access_key, self.config.access_secret,
         calling_format=connection.OrdinaryCallingFormat())
     # Always use our internal cacerts.txt file. This fixes an issue with the
     # PyInstaller-based frozen distribution, while allowing us to continue to
     # verify certificates and use a secure connection.
     gs_connection.ca_certificates_file = utils.get_cacerts_path()
     try:
         return gs_connection.get_bucket(self.config.bucket)
     except boto.exception.GSResponseError as e:
         if e.status == 404:
             logging.info('Creating bucket: {}'.format(self.config.bucket))
             return gs_connection.create_bucket(self.config.bucket)
         raise
 def bucket(self):
     if self.config.oauth2:
         enable_oauth2_auth_handler()
     gs_connection = boto.connect_gs(
         self.config.access_key, self.config.access_secret,
         calling_format=connection.OrdinaryCallingFormat())
     # Always use our internal cacerts.txt file. This fixes an issue with the
     # PyInstaller-based frozen distribution, while allowing us to continue to
     # verify certificates and use a secure connection.
     gs_connection.ca_certificates_file = utils.get_cacerts_path()
     try:
         return gs_connection.get_bucket(self.config.bucket)
     except boto.exception.GSResponseError as e:
         if e.status == 404:
             logging.info('Creating bucket: {}'.format(self.config.bucket))
             return gs_connection.create_bucket(self.config.bucket)
         raise
Exemple #9
0
 def create_service(self, host):
     credentials = oauth.get_or_create_credentials(scope=OAUTH_SCOPES,
                                                   storage_key=STORAGE_KEY)
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     http = credentials.authorize(http)
     # Kintaro's server doesn't seem to be able to refresh expired tokens
     # properly (responds with a "Stateless token expired" error). So we
     # manage state ourselves and refresh slightly more often than once
     # per hour.
     now = datetime.datetime.now()
     if self._last_run is None \
         or now - self._last_run >= datetime.timedelta(minutes=50):
         credentials.refresh(http)
         self._last_run = now
     url = DISCOVERY_URL.replace('{host}', host)
     return discovery.build('content',
                            'v1',
                            http=http,
                            discoveryServiceUrl=url)
Exemple #10
0
 def create_service(api='drive', version='v2'):
     credentials = oauth.get_or_create_credentials(
         scope=OAUTH_SCOPE, storage_key='Grow SDK')
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     http = credentials.authorize(http)
     return discovery.build(api, version, http=http)
 def http(self):
     credentials = oauth.get_or_create_credentials(scope=OAUTH_SCOPE,
                                                   storage_key=STORAGE_KEY)
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     http = credentials.authorize(http)
     return http
Exemple #12
0
 def create_service():
     credentials = oauth.get_or_create_credentials(
         scope=OAUTH_SCOPE, storage_key='Grow SDK')
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     http = credentials.authorize(http)
     return discovery.build('drive', 'v2', http=http)
 def http(self):
     credentials = oauth.get_or_create_credentials(
         scope=OAUTH_SCOPE, storage_key=STORAGE_KEY)
     http = httplib2.Http(ca_certs=utils.get_cacerts_path())
     http = credentials.authorize(http)
     return http