-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
36 lines (29 loc) · 1.03 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from PyPDF2 import PdfReader
from docx import Document
def load_log_file(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
return file.readlines()
except Exception as e:
return [f"Error loading file: {str(e)}"]
def load_text_file(file_path):
try:
with open(file_path, 'r', encoding='utf-8') as file:
return file.readlines()
except Exception as e:
return [f"Error loading file: {str(e)}"]
def load_pdf_file(file_path):
try:
pdf_reader = PdfReader(file_path)
pages_content = []
for page in pdf_reader.pages:
pages_content.append(page.extract_text())
return "\n".join(pages_content).splitlines()
except Exception as e:
return [f"Error loading PDF file: {str(e)}"]
def load_word_file(file_path):
try:
doc = Document(file_path)
return [para.text for para in doc.paragraphs if para.text.strip() != ""]
except Exception as e:
return [f"Error loading Word file: {str(e)}"]