import importlib from .base import BaseParser class ParserSelector: def __init__(self): self.store_keywords = { 'lidl': ['lidl'], 'konzum': ['konzum'], 'plodine': ['plodine'], 'studenac': ['studenac'], 'spar': ['spar'], 'kaufland': ['kaufland'] } def get_store_parser(self, text: str): text_lower = text.lower() for store, keywords in self.store_keywords.items(): if any(kw in text_lower for kw in keywords): try: module = importlib.import_module(f"receipt_processor.parsers.{store}_parser") for attr_name in dir(module): attr = getattr(module, attr_name) try: if issubclass(attr, BaseParser) and attr != BaseParser: return attr() except TypeError: continue except ModuleNotFoundError: continue raise ValueError(f"No parser found for text: {text[:50]}...")