blubbblülüllü
This commit is contained in:
@@ -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
|
||||
@@ -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"))
|
||||
Reference in New Issue
Block a user