Package: rdmhelper
Installingpip install rdmhelperSeafileAPI documentation:https://download.seafile.com/published/web-api/home.mdUsagefromrdmhelper.keeperimportSeafilesf=Seafile(server=server,username=username,password=password)View Account detailssf.account_info()List repositoriesSeafile is organized in repositories. You need to pass a reposirory id to most functionssf.repo_list()repo=sf.repo_list()[0].get('id')Make dirresp=sf.folder_create(repo,'testfolder')Upload Folderadd_date=True will append the current date to the name of the uploaded folder.
add_date_recursive = True will append the current date to all files in the uploaded folder and subfolders.sf.folder_upload(repo,local_dir='data/',remote_dir='/testfolder',add_date=True,add_date_recursive=False)List folder contentcontent_json=sf.folder_list_content(repo,'/testfolder')Show Folder Detaildetail_json=sf.folder_detail(repo,'testfolder/data_2021_07_14/subfolder')Delete folderresp=sf.folder_delete(repo,'testfolder2')Rename foldersf.folder_rename(repo,path='testfolder/data_2021_07_14/subfolder',new_name='subfolder_renamed')Download foldersf.folder_download(repo,remote_dir='testfolder/data_2021_07_14/subfolder',local_dir='downloads')Share repositoryresp=sf.repo_share(repo,userlist=['hbenne@gmx.at','existiertnicht@gmail.com'],permissions='rw')Revoke permissions:resp=sf.repo_unshare(repo,user='hbenne@gmx.at')Show file detailssf.file_info(repo,file='/testfolder/data_2021_07_14/test.csv')Search fileresults_json=sf.file_search(repo,file='data.txt')Read fileimportpandasaspdurl=sf.downloadlink(repo,'/testfolder/data_2021_07_14/test.csv')df=pd.read_csv(url)print(df.head())If the example above does not run on your mac have a look at:https://stackoverflow.com/questions/50236117/scraping-ssl-certificate-verify-failed-error-for-http-en-wikipedia-orgDownload filesf.file_download(repo,file='/testfolder/data_2021_07_14/test.csv',local_dir='downloads/data/')Delete fileresp=sf.file_delete(repo,file='/testfolder/data_2021_07_14/test.csv')NextcloudAPI documentation:https://docs.nextcloud.com/server/latest/developer_manual/client_apis/index.htmlApp passwordIt is recommended not to use your login password.
You can create app specific passwords: Settings -> security -> new app password.Usagefromrdmhelper.nextcloudimportNextcloudcloud=Nextcloud(server='https://SERVERNAME/remote.php/dav/files/',username=USERNAME,password=PASSWORD,webdav_token=WEBDAV_TOKEN)In the official nextcloud documentation the webdav_token is referred to as "username". But it is different from the login name and can be found in settings -> WebDAV.List files/folderslist root directorycloud.list('')listhttps://SERVERNAME/apps/files/?dir=/WebdavTest/subfoldercloud.list_dir('WebdavTest/subfolder')Make DirCreate directory named New in WebdavTestcloud.make_dir('WebdavTest/neu')Upload fileUpload Datei.md from the local dir data/ to WebdavTest/subfolder.
If add_date is True a timestamp will be added to the filename.cloud.upload_file(local_file='data/Datei.md',path='WebdavTest/subfolder',filename='Datei1.md',add_date=True)Upload folderUpload the local folder ./Testfolder into the WebdavTest folder on Nextcloud.
Add a timestamp to the foldername if add_date is True.
Add a timestamp to all files in the folder if add_date_recursive is True.cloud.upload_folder(local_folder='Testfolder',target_folder='WebdavTest',add_date=True,add_date_recursive=False)Download filecloud.download_file(path='WebdavTest/',filename='kwg_mpg.xlsx',target_dir='data/')Read fileRead Excel file from Nextcloud.importpandasaspddf=pd.read_excel(cloud.read_file(path='WebdavTest/',filename='kwg_mpg.xlsx'),engine='openpyxl')Read CSVimportpandasaspdfromioimportBytesIOcsv=cloud.read_file(path='WebdavTest/Subfolder/',filename='datei.csv')df=pd.read_csv(BytesIO(csv))Delete file/ folderDelete filecloud.delete_file(path='WebdavTest/subfolder/Datei.md')Delete foldercloud.delete_file(path='WebdavTest/subfolder/Datei.md')