from commands.base_command import Command from controllers import ScraperController from exceptions import ScraperException class ScrapeCommand(Command): def __init__(self, controller: ScraperController, strategy_name: str): self.controller = controller self.strategy_name = strategy_name self.scrape_result = None self.saved_path = None def execute(self): try: self.scrape_result = self.controller.execute_scrape(self.strategy_name) self.saved_path = self.controller.save_data(self.scrape_result, self.strategy_name) return self.scrape_result, self.saved_path except ScraperException as e: raise e def undo(self): if self.saved_path and self.controller.delete_data(self.saved_path): print(f"Successfully undone: deleted {self.saved_path}") return True return False