aboutsummaryrefslogtreecommitdiff
path: root/src/uploader.py
diff options
context:
space:
mode:
authorgabrielgio <gabriel.giovanini@pm.me>2021-07-14 21:23:44 +0200
committergabrielgio <gabriel.giovanini@pm.me>2021-07-14 21:23:44 +0200
commit4d43e402b2b4e27bbbbfe557216d95963a27af72 (patch)
tree46f3013be10a1062280d64052bcb654d67084f91 /src/uploader.py
parent6887fcc0e42b1a64ed80f8565fe3099aaa818930 (diff)
downloadreddit-nextcloud-importer-4d43e402b2b4e27bbbbfe557216d95963a27af72.tar.gz
reddit-nextcloud-importer-4d43e402b2b4e27bbbbfe557216d95963a27af72.tar.bz2
reddit-nextcloud-importer-4d43e402b2b4e27bbbbfe557216d95963a27af72.zip
feat: Add nextcloud path param
Add a new param to input the nextcloud root path.
Diffstat (limited to 'src/uploader.py')
-rw-r--r--src/uploader.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/uploader.py b/src/uploader.py
new file mode 100644
index 0000000..7c7641a
--- /dev/null
+++ b/src/uploader.py
@@ -0,0 +1,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)