def __init__(self, path, bot): self.bot = bot self.path = path self.last_stamp = None self.file = None self.watching = False self.ui = ConsoleAdviser() super().__init__()
class BotParser(LogParser, PatternMatchingEventHandler): patterns = ["*Power.log"] def __init__(self, path, bot): self.bot = bot self.path = path self.last_stamp = None self.file = None self.watching = False self.ui = ConsoleAdviser() super().__init__() def set_ui_handler(self, handler): self.ui = handler def on_modified(self, event): print("Log change found at", str(datetime.now())) self.last_stamp = self.read(self.file, self.last_stamp) print("Reading completed at", str(datetime.now())) next_step = None if self.is_our_turn(): next_step = self.bot.next(self.games[-1]) self.ui.show_advice(next_step) def watch(self): observer = PollingObserver(0.1) observer.schedule(self, self.path) observer.start() self.file = open(self.path + "\Power.log", "r") self.on_modified(None) self.watching = True def stop(self): self.watching = False self.last_stamp = None self.file.close() def is_our_turn(self): # TODO: check if our turn return True