aboutsummaryrefslogtreecommitdiff
path: root/importer/uploader.py
blob: 7c7641aa2a2172b2e71629be8c77d6fddd0a50ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from functools import reduce

from nextcloud import NextCloud


def _create_folder(folder: str, nxc: NextCloud) -> str:
    nxc.create_folder(folder, True)
    return folder


def create_folders(path: str, nxc: NextCloud):
    # remove first "/" if there is one.
    path = path if path[0] != '/' else path[1:]
    folders = path.split("/")
    reduce(lambda x, y: _create_folder(f"{x}/{y}", nxc), folders, "")


def upload_file(local_filename: str, remote_filename: str, nxc: NextCloud):
    nxc.upload_file(local_filename, remote_filename)