def download(self, entry_or_id_or_url, file_path, extra_params=None, auth_token=None, **kwargs): """Downloads a file from the Document List to local disk. Note: to download a file in memory, use the GetFileContent() method. Args: entry_or_id_or_url: gdata.docs.data.DocsEntry or string representing a resource id or URL to download the document from (such as the content src link). file_path: str The full path to save the file to. extra_params: dict (optional) A map of any further parameters to control how the document is downloaded/exported. For example, exporting a spreadsheet as a .csv: extra_params={'gid': 0, 'exportFormat': 'csv'} auth_token: (optional) gdata.gauth.ClientLoginToken, AuthSubToken, or OAuthToken which authorizes this client to edit the user's data. kwargs: Other parameters to pass to self._download_file(). Raises: gdata.client.RequestError if the download URL is malformed or the server's response was not successful. ValueError if entry_or_id_or_url was a resource id for a filetype in which the download link cannot be manually constructed (e.g. pdf). """ if isinstance(entry_or_id_or_url, gdata.docs.data.DocsEntry): url = entry_or_id_or_url.content.src else: if gdata.docs.data.RESOURCE_ID_PATTERN.match(entry_or_id_or_url): url = gdata.docs.data.make_content_link_from_resource_id( entry_or_id_or_url) else: url = entry_or_id_or_url if extra_params is not None: if 'exportFormat' in extra_params and url.find('/Export?') == -1: raise gdata.client.Error, ( 'This entry type cannot be exported ' 'as a different format.') if 'gid' in extra_params and url.find('spreadsheets') == -1: raise gdata.client.Error, 'gid param is not valid for this doc type.' url += '&' + urllib.urlencode(extra_params) self._download_file(url, file_path, auth_token=auth_token, **kwargs)
def download(self, entry_or_id_or_url, file_path, extra_params=None, auth_token=None, **kwargs): """Downloads a file from the Document List to local disk. Note: to download a file in memory, use the GetFileContent() method. Args: entry_or_id_or_url: gdata.docs.data.DocsEntry or string representing a resource id or URL to download the document from (such as the content src link). file_path: str The full path to save the file to. extra_params: dict (optional) A map of any further parameters to control how the document is downloaded/exported. For example, exporting a spreadsheet as a .csv: extra_params={'gid': 0, 'exportFormat': 'csv'} auth_token: (optional) gdata.gauth.ClientLoginToken, AuthSubToken, or OAuthToken which authorizes this client to edit the user's data. kwargs: Other parameters to pass to self._download_file(). Raises: gdata.client.RequestError if the download URL is malformed or the server's response was not successful. ValueError if entry_or_id_or_url was a resource id for a filetype in which the download link cannot be manually constructed (e.g. pdf). """ if isinstance(entry_or_id_or_url, gdata.docs.data.DocsEntry): url = entry_or_id_or_url.content.src else: if gdata.docs.data.RESOURCE_ID_PATTERN.match(entry_or_id_or_url): url = gdata.docs.data.make_content_link_from_resource_id( entry_or_id_or_url) else: url = entry_or_id_or_url if extra_params is not None: if 'exportFormat' in extra_params and url.find('/Export?') == -1: raise gdata.client.Error, ('This entry type cannot be exported ' 'as a different format.') if 'gid' in extra_params and url.find('spreadsheets') == -1: raise gdata.client.Error, 'gid param is not valid for this doc type.' url += '&' + urllib.urlencode(extra_params) self._download_file(url, file_path, auth_token=auth_token, **kwargs)
def sheetName(self, url): sheet="BASICIMPORT" offset=0 if url.find('?') > -1: sheet = url.split('?')[1] offset = url.split('?')[2] sheet = urllib.url2pathname( sheet ) return sheet, offset
def TokenFromUrl(url): """Extracts the AuthSub token from the URL. Returns the raw token value. Args: url: str The URL or the query portion of the URL string (after the ?) of the current page which contains the AuthSub token as a URL parameter. """ if url.find('?') > -1: query_params = url.split('?')[1] else: query_params = url for pair in query_params.split('&'): if pair.startswith('token='): return pair[6:] return None