blubbblülüllü

This commit is contained in:
Jonas Braus
2024-12-10 19:41:01 +01:00
parent 055657939e
commit c5a8e9c5e3
2 changed files with 53 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import os, pymupdf
def read_files(path, output, filetypes=None):
if filetypes is None:
filetypes = ["pdf", "txt", "png", "jpg", "mp3"]
for root, dirs, files in os.walk(path):
for file in files:
if (file_type := file.split(".")[-1]) in filetypes:
output.append((file_type, os.path.join(path, file)))
for folder in dirs:
read_files(os.path.join(path, folder), output)
break
def extract_pdf_content(pdf_datei):
doc = pymupdf.open(pdf_datei)
a = ""
for page in doc:
a += page.get_text()
return a
+31
View File
@@ -0,0 +1,31 @@
import pymupdf
import os
import lib
import json
def retrieve_file_contents(path):
file_extraction_functions = {
"pdf": lambda path: lib.extract_pdf_content(path),
"jpg": lambda path: "",
"png": lambda path: "",
"txt": lambda path: lib.extract_pdf_content(path),
"mp3": lambda path: "test mp3"
}
lib.read_files(path, files := [])
contents = []
for file in files:
content = file_extraction_functions[file[0]](file[1])
contents.append({
"type": file[0],
"path": file[1],
"content": content
})
return contents
contents = retrieve_file_contents("C:\\SoftwareEng")
print(json.dumps(contents, indent="\t"))