Skip to content
Snippets Groups Projects
Commit 698fdf54 authored by Marvin Winkens's avatar Marvin Winkens
Browse files

first init

parents
No related branches found
No related tags found
No related merge requests found
fingerhuete_*/
__pycache__
.idea
from rembg import remove
from webdavsync import pull, push, get_info, list_b2drop
from rembg import remove as remove_bg
import os
import threading
import time
cloud_path_in = "Fingerhüte-Roh"
local_path_in = "./fingerhuete_in2"
local_path_out = "./fingerhuete_processed2"
cloud_path_out = "Fingerhüte_processed2"
def process_single(path_in, path_out):
with open(path_in, 'rb') as i:
with open(path_out, 'wb') as o:
img = i.read()
output = remove_bg(img)
o.write(output)
def process(path_in, path_out):
tries = 0
while tries != 5:
tries += 1
prefix = "rembg_"
already_processed = set(os.listdir(path_out))
already_processed_original = {name[len(prefix):] for name in already_processed}
all_processable = set(os.listdir(path_in))
to_process = all_processable - already_processed_original
print(f'processing {len(to_process)} files')
if len(to_process) == 0:
print("trying again in 10 seconds")
time.sleep(10)
continue
tries = 0
for fname in to_process:
try:
process_single(f"{path_in}/{fname}", f"{path_out}/{prefix}{fname}")
except Exception as e:
print(f"error while processing file {fname}")
print(e)
def pull_data():
pull(cloud_path_in, local_path_in)
def push_data():
push_count = 0
while push_count != 5:
push_count += 1
try:
do_push = push(cloud_path_out, local_path_out)
if do_push:
push_count = 0
except Exception as e:
print(e)
push_count = 0
time.sleep(60) # sleep for a minute
def main():
# b2drop_list = list_b2drop()
# for el in b2drop_list:
# print(el["path"])
t1 = threading.Thread(target=pull_data)
t2 = threading.Thread(target=process, args=(local_path_in, local_path_out))
t3 = threading.Thread(target=push_data)
t1.start()
t2.start()
t3.start()
t1.join()
print("finished pulling")
t2.join()
print("finished processing")
t3.join()
print("finished pushing")
if __name__ == "__main__":
main()
from webdav3.client import Client
username = "1686b184-4d7a-45ba-8cba-4c8aef619886"
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 list_b2drop():
return client.list(get_info=True)
def get_info(cloud_path: str):
return client.info(cloud_path)
def pull(cloud_path, local_path):
return client.pull(cloud_path, local_path)
def push(cloud_path, local_path):
return client.push(cloud_path, local_path)
def upload(cloud_path, local_path):
return client.upload(cloud_path, local_path)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment