From bb1bd62250822cacc694236a686e66b228c438d2 Mon Sep 17 00:00:00 2001 From: crunk Date: Mon, 13 May 2024 21:02:23 +0200 Subject: [PATCH] file crawler for annotations,descriptions,tags --- verse/file_crawler.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/verse/file_crawler.py b/verse/file_crawler.py index 8ba8024..9e5456b 100644 --- a/verse/file_crawler.py +++ b/verse/file_crawler.py @@ -1 +1,22 @@ +import os + +import magic +from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES + from models.distribusi_file_model import DistribusiFiles + +MIME_TYPE = magic.Magic(mime=True) + + +def distribusi_file_with_type(full_path): + mime = MIME_TYPE.from_file(full_path) + type_, subtype = mime.split("/") + if type_ in FILE_TYPES: + print(f"distribusi file:{full_path} type:{type_}") + + +for root, dirs, files in os.walk("stash", topdown=True): + files = list(filter(lambda f: not f.startswith("."), files)) + for file in files: + full_path = os.path.join(root, file) + distribusi_file_with_type(full_path)