tweaked some code after looking at real images and added a readme
This commit is contained in:
@@ -3,6 +3,7 @@ Shared configuration, logging, and utilities for the FCCS extraction tool.
|
||||
"""
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import argparse
|
||||
import configparser
|
||||
@@ -62,6 +63,40 @@ def load_folder_list(path):
|
||||
return folders
|
||||
|
||||
|
||||
def build_folder_patterns(templates):
|
||||
"""
|
||||
Convert folder template strings into regex patterns for matching.
|
||||
|
||||
Templates use YYYY as a year placeholder (e.g. 'YYYY Tax Documents').
|
||||
Non-recurring folders (no YYYY) are matched literally.
|
||||
A built-in pattern for 'UltraTax CS MM-DD-YYYY' is always included.
|
||||
|
||||
Returns a list of (compiled_regex, template_name) tuples, sorted
|
||||
longest-first to prevent partial matches.
|
||||
"""
|
||||
patterns = []
|
||||
|
||||
# Built-in: UltraTax CS folders (auto-generated by UltraTax integration)
|
||||
patterns.append((
|
||||
re.compile(r"UltraTax CS \d{2}-\d{2}-\d{4}$"),
|
||||
"UltraTax CS",
|
||||
))
|
||||
|
||||
for tmpl in templates:
|
||||
if "YYYY" in tmpl:
|
||||
# Replace YYYY with 4-digit year pattern, escape the rest
|
||||
parts = tmpl.split("YYYY")
|
||||
regex_str = re.escape(parts[0]) + r"\d{4}" + re.escape(parts[1])
|
||||
else:
|
||||
# Non-recurring folder — exact match
|
||||
regex_str = re.escape(tmpl)
|
||||
patterns.append((re.compile(regex_str + "$"), tmpl))
|
||||
|
||||
# Sort by regex pattern length (longest first) to avoid partial matches
|
||||
patterns.sort(key=lambda p: len(p[0].pattern), reverse=True)
|
||||
return patterns
|
||||
|
||||
|
||||
def load_lines(path):
|
||||
"""Read non-blank, non-comment lines from a file."""
|
||||
if not os.path.exists(path):
|
||||
|
||||
Reference in New Issue
Block a user