def load_remote_to_dataframe(self) -> pd.DataFrame: if (not self._abs_file_url) | (not self._username) | ( not self._password) | (not self._url) | (not self._document): data = f'- username: {self._username}\n' \ f'- password: {self._password}\n' \ f'- url: {self._url}\n' \ f'- document: {self._document}\n' \ f'- full_url: {self._abs_file_url}\n' raise Exception(f'Dati richiesti mancanti\n{data}') user_credentials = UserCredential(self._username, self._password) with tempfile.TemporaryDirectory() as local_path: file_name = os.path.basename(self._abs_file_url) with open(os.path.join(local_path, file_name), 'wb') as local_file: file = File.from_url(self._abs_file_url).with_credentials( user_credentials).download(local_file).execute_query() # print("'{0}' file has been downloaded into {1}".format(file.serverRelativeUrl, local_file.name)) df = pd.read_excel(local_file.name, engine='openpyxl', converters={'ProvinciaResidenza': str}) df['DataDiNascita'] = pd.to_datetime( df.DataNascita).dt.strftime('%Y-%m-%d') return df
import os import tempfile from office365.sharepoint.files.file import File from tests import test_client_credentials, test_site_url abs_file_url = "{site_url}sites/team/Shared Documents/big_buck_bunny.mp4".format( site_url=test_site_url) with tempfile.TemporaryDirectory() as local_path: file_name = os.path.basename(abs_file_url) with open(os.path.join(local_path, file_name), 'wb') as local_file: file = File.from_url(abs_file_url).with_credentials( test_client_credentials).download(local_file).execute_query() print("'{0}' file has been downloaded into {1}".format( file.serverRelativeUrl, local_file.name))
def test4_get_file_from_absolute_url(self): file_abs_url = self.client.base_url + self.__class__.target_file.serverRelativeUrl file = File.from_url(file_abs_url).with_credentials(self.client_credentials).get().execute_query() self.assertIsNotNone(file.serverRelativeUrl)