34 lines
868 B
Python
34 lines
868 B
Python
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: lib.extract_image_content(path),
|
|
"png": lambda path: lib.extract_image_content(path),
|
|
"txt": lambda path: lib.extract_pdf_content(path),
|
|
"mp3": lambda path: lib.extract_mp3_content(path),
|
|
}
|
|
|
|
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],
|
|
"filename": file[2],
|
|
"content": content
|
|
})
|
|
|
|
return contents
|
|
|
|
contents = retrieve_file_contents("C:\\Users\\afist\\Downloads\\SoftwareEng")
|
|
|
|
|
|
|
|
print(json.dumps(contents, indent="\t")) |