Skip to main content

Manage files in MPG Cloudservices.

Project description

Installing

pip install mpg-cloud

Seafile

API documentation: https://download.seafile.com/published/web-api/home.md

Usage

from mpg_cloud import Seafile
sf = Seafile(
    server=server, 
    username=username, 
    password=password)

View Account details

sf.account_info()

List repositories

Seafile is organized in repositories. You need to pass a reposirory id to most functions

sf.repo_list()
repo = sf.repo_list()[0].get('id')

Make dir

 resp = sf.folder_create(repo, 'testfolder')

Upload Folder

add_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 content

content_json = sf.folder_list_content(repo, '/testfolder')

Show Folder Detail

detail_json = sf.folder_detail(repo, 'testfolder/data_2021_07_14/subfolder')

Delete folder

resp = sf.folder_delete(repo, 'testfolder2')

Rename folder

sf.folder_rename(repo, path='testfolder/data_2021_07_14/subfolder', new_name='subfolder_renamed')

Download folder

sf.folder_download(repo, remote_dir='testfolder/data_2021_07_14/subfolder', local_dir='downloads')

Share repository

resp = 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 details

sf.file_info(repo, file='/testfolder/data_2021_07_14/test.csv')

Search file

results_json = sf.file_search(repo,file='data.txt')

Read file

import pandas as pd
url = 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-org

Download file

sf.file_download(repo, file='/testfolder/data_2021_07_14/test.csv', local_dir='downloads/data/')

Delete file

resp = sf.file_delete(repo, file='/testfolder/data_2021_07_14/test.csv')

Nextcloud

API documentation: https://docs.nextcloud.com/server/latest/developer_manual/client_apis/index.html

App password

It is recommended not to use your login password. You can create app specific passwords: Settings -> security -> new app password.

Usage

from mpg_cloud import Nextcloud
cloud = 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/folders

list root directory

cloud.list('')

list https://SERVERNAME/apps/files/?dir=/WebdavTest/subfolder

cloud.list_dir('WebdavTest/subfolder')

Make Dir

Create directory named New in WebdavTest

cloud.make_dir('WebdavTest/neu')

Upload file

Upload 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 folder

Upload 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 file

cloud.download_file(
    path='WebdavTest/', 
    filename='kwg_mpg.xlsx', 
    target_dir='data/'
    )

Read file

Read Excel file from Nextcloud.

import pandas as pd
df = pd.read_excel(
    cloud.read_file(path='WebdavTest/', filename='kwg_mpg.xlsx'), engine='openpyxl'
    )

Read CSV

import pandas as pd
from io import BytesIO
csv = cloud.read_file(path='WebdavTest/Subfolder/', filename='datei.csv')
df = pd.read_csv(BytesIO(csv))

Delete file/ folder

Delete file

cloud.delete_file(path='WebdavTest/subfolder/Datei.md')

Delete folder

cloud.delete_file(path='WebdavTest/subfolder/Datei.md')

Known issues

Currently lxml must be installed manually.

pip install lxml

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mpg_cloud-1.0.1.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

mpg_cloud-1.0.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file mpg_cloud-1.0.1.tar.gz.

File metadata

  • Download URL: mpg_cloud-1.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.5

File hashes

Hashes for mpg_cloud-1.0.1.tar.gz
Algorithm Hash digest
SHA256 522efddf848626ffac266491028ef5f9520b0b9240ffeb1f2648837f395857a9
MD5 27db1915524ebb69f06e42fae4d06068
BLAKE2b-256 80aea7ed9449701132298ce6c66da46ddc4b16e05dbab0bece20105293868772

See more details on using hashes here.

File details

Details for the file mpg_cloud-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: mpg_cloud-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.5

File hashes

Hashes for mpg_cloud-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3146697dd9ec9cab473cbf7a5a3f26da948353253a1b59aaf8e6218e84018d0d
MD5 7eb3f175b38f0926f8ba426010250bd7
BLAKE2b-256 f1318bb10406f69cdcc69b6b9125df5cd12b500076ce071d539754ed46aeb111

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page