intead of this pattern Week X 20XX, consider week X. and it not case senstive and need…
- User
intead of this pattern Week X 20XX, consider week X. and it not case senstive and need to remove any symbols or additional space found in the ocr data. and in excel file save "Week + week number from the OCR data
Assistant
Below is a minimal patch that does exactly what you asked:
• looks for the first occurrence of “week” (case-insensitive) followed by a number
• strips every non-alphanumeric character from the OCR text before the search
• writes the week into the Excel file as “Week ” (e.g. “Week 1”)Only two small code blocks change – everything else stays the same.
- New helper (drop it in just above
process_timesheets)
def extract_week_from_text(text: str) -> str: """ Return the first week number found in the OCR text. Format returned: 'Week <number>' (e.g. 'Week 1') """ # 1. Remove every character that is not a letter, digit or space cleaned = re.sub(r'[^A-Za-z0-9\s]', ' ', text) # 2. Case-insensitive search for 'week' followed by digits m = re.search(r'week\s+(\d+)', cleaned, flags=re.IGNORECASE) if m: return f"Week {int(m.group(1))}" return "Week Unknown"
- Two tiny edits inside
process_timesheets
a) Remove the old filename-based week extraction:
# OLD (delete these two lines) file_match = re.match(r"(.+?)_Week(\d+)_\d+\.(png|jpg|jpeg)$", filename, re.IGNORECASE) if file_match: name, week = file_match.group(1), file_match.group(2) else: name = filename.rsplit('.', 1)[0]Replace with:
# NEW name = os.path.splitext(filename)[0] # keep only the base nameb) Call the new helper and use its result:
# NEW week = extract_week_from_text(text)
That’s it – the Excel file will now contain “Week 1”, “Week 2”, … taken directly from the OCR text, regardless of how the image is named.
- New helper (drop it in just above
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.