From 40906944716b50a3684919f4a3e2c505c463a10f Mon Sep 17 00:00:00 2001
From: mwinkens <m.winkens@fz-juelich.de>
Date: Fri, 12 May 2023 11:44:59 +0200
Subject: [PATCH] restructure code and add jupyter notebook

---
 .gitignore          |  1 +
 b2drop-webdav.ipynb |  0
 fingerhuete.py      | 16 +++++++++++-----
 webdavsync.py       | 21 ++++++++++++---------
 4 files changed, 24 insertions(+), 14 deletions(-)
 create mode 100644 b2drop-webdav.ipynb

diff --git a/.gitignore b/.gitignore
index 5fef0ad..751bf49 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 fingerhuete_*/
 __pycache__
 .idea
+.eudat-key
diff --git a/b2drop-webdav.ipynb b/b2drop-webdav.ipynb
new file mode 100644
index 0000000..e69de29
diff --git a/fingerhuete.py b/fingerhuete.py
index 705ab38..8fca95b 100644
--- a/fingerhuete.py
+++ b/fingerhuete.py
@@ -1,5 +1,5 @@
 from rembg import remove
-from webdavsync import pull, push, get_info, list_b2drop
+from webdavsync import pull, push, get_info, list_b2drop, connect_webdav_b2drop
 from rembg import remove as remove_bg
 import os
 import threading
@@ -60,11 +60,17 @@ def push_data():
             time.sleep(60)  # sleep for a minute
 
 
-
 def main():
-    # b2drop_list = list_b2drop()
-    # for el in b2drop_list:
-    #    print(el["path"])
+    username = "1686b184-4d7a-45ba-8cba-4c8aef619886"
+    try:
+        f = open(".eudat-key", "r")
+    except OSError as e:
+        print(e)
+        print("Make sure the file .eudat-key does exist and contains your B2DROP key")
+    webdav_pw = f.read()
+    f.close()
+    connect_webdav_b2drop(username, webdav_pw)
+
     t1 = threading.Thread(target=pull_data)
     t2 = threading.Thread(target=process, args=(local_path_in, local_path_out))
     t3 = threading.Thread(target=push_data)
diff --git a/webdavsync.py b/webdavsync.py
index 6f77511..2c6b392 100644
--- a/webdavsync.py
+++ b/webdavsync.py
@@ -1,16 +1,19 @@
 from webdav3.client import Client
 
-username = "1686b184-4d7a-45ba-8cba-4c8aef619886"
+client: Client
 
-options = {
-    'webdav_hostname': f"https://b2drop.eudat.eu/remote.php/dav/files/{username}",
-    'webdav_login': username,
-    'webdav_password': "CYFfS-Ff7FG-yke27-XkjTe-dWJrw",
-    'verbose': True,
-    'webdav_timeout': 60*4,  # 10 minutes
-}
 
-client = Client(options)
+def connect_webdav_b2drop(username, webdav_pw):
+    global client
+
+    options = {
+        'webdav_hostname': f"https://b2drop.eudat.eu/remote.php/dav/files/{username}",
+        'webdav_login': username,
+        'webdav_password': webdav_pw,
+        'verbose': True,
+        'webdav_timeout': 60 * 4,  # 10 minutes
+    }
+    client = Client(options)
 
 
 def list_b2drop():
-- 
GitLab