Notes
Notes - notes.io |
class DocumentProcessor:
def __init__(self):
self.documents = []
self.setup_ui()
def setup_ui(self):
window = tk.Tk()
window.title("Document Processor")
window.geometry("500x250")
tk.Label(window, text="Document Quote Review Automation", font=("Arial", 14)).pack(pady=10)
upload_btn = tk.Button(window, text="Upload Documents", command=self.upload_documents, height=2, width=20)
upload_btn.pack(pady=10)
process_btn = tk.Button(window, text="Process & Save to Excel", command=self.process_and_save, height=2, width=20)
process_btn.pack(pady=10)
window.mainloop()
def upload_documents(self):
file_paths = fd.askopenfilenames(title='Select documents', filetypes=[("PDF files", "*.pdf")])
self.documents.extend(file_paths)
print(f"{len(file_paths)} file(s) uploaded.")
def process_and_save(self):
workbook = Workbook()
sheet = workbook.active
sheet.append(["Document Path", "Type", "Quote Number", "Total", "Quote Date", "Solution ID"])
for doc_path in self.documents:
doc_type, data = self.process_document(doc_path)
sheet.append([doc_path, doc_type] + list(data.values()))
workbook.save("DocumentAnalysis.xlsx")
print("Analysis saved to DocumentAnalysis.xlsx.")
def process_document(self, doc_path):
try:
with open(doc_path, 'rb') as pdf_file:
pdf_reader = PyPDF2.PdfReader(pdf_file)
all_text = " ".join(page.extract_text() for page in pdf_reader.pages)
if "Quote No." in all_text:
return "USQuote", self.extract_us_quote_data(all_text)
elif "Quote Date:" in all_text:
return "EMEAQuote", self.extract_emea_quote_data(all_text)
elif "Solution ID" in all_text:
return "SolutionID", self.extract_solution_id_data(all_text)
except Exception as e:
print(f"Error processing {doc_path}: {e}")
return "Unknown", {}
def extract_us_quote_data(self, text):
data = {
"Quote Number": self.find_with_regex(text, r"Quote No. n([d|,|.]+) n"),
"Total": self.find_with_regex(text, r"Totaln$([d|,|.]+)n"),
"Quote Date": self.find_with_regex(text, r"Quoted Onn([a-zA-Z]+. [0-9]+, [0-9]+) n"),
"Solution ID": self.find_with_regex(text, r"Solution IDn([d|,|.]+)"),
}
return data
def extract_emea_quote_data(self, text):
data = {
"Quote Number": self.find_with_regex(text, r"Quote/Source Ref: ([0-9]+.? [0-9]+?)"),
"Total": self.find_with_regex(text, r"Total ([d|,|.]+)"),
"Quote Date": self.find_with_regex(text, r"Quote Date: ([0-9]+- [0-9]+- [0-9]+)"),
"Solution ID": "", # Assuming EMEA quotes might not have a Solution ID directly mentioned
}
return data
def extract_solution_id_data(self, text):
# Assuming a pattern for Solution IDs, though not specified in the example
data = {
"Solution ID": self.find_with_regex(text, r"Solution ID: ([wd]+)"),
"Quote Number": "",
"Total": "",
"Quote Date": "",
}
return data
@staticmethod
def find_with_regex(text, pattern):
match = re.search(pattern, text, re.MULTILINE)
return match.group(1) if match else ""
if __name__ == "__main__":
DocumentProcessor()
|
Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 12 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team