from telebot import formatting import time, threading, schedule from pythonFortniteStatus.FortniteStatus import * __polling_interval__ = 5 fortniteStatus = FortniteStatus() class Observer: def update(self, fortniteStatus) -> None: pass class FortniteStatusWrapper: observers = [] fortniteStatus = None def __init__(self): schedule.every(__polling_interval__).seconds.do(self.__readStatus) threading.Thread(target=self.__scheduleHandler, name='fortnite_status_scheduler', daemon=True).start() def __scheduleHandler(self): while True: schedule.run_pending() time.sleep(1) def __readStatus(self): serviceStatusTmp = fortniteStatus.getStatus() if serviceStatusTmp != self.fortniteStatus: self.notify(serviceStatusTmp) self.fortniteStatus = serviceStatusTmp def notify(self, fortniteStatus): print("Fortnite status changed, notifying observers") for observer in self.observers: observer.update(fortniteStatus) def attach(self, observer: Observer): self.observers.append(observer)