from telebot import formatting import time import asyncio from pythonFortniteStatus.FortniteStatus import * # Polling interval in seconds __polling_interval__ = 5 * 60 # 5 minutes class FortniteStatusObserver: async def update(self, fortnite_status) -> None: pass class FortniteStatusNotifier: __fortnite_status_observer: FortniteStatusObserver __fortnite_status: FortniteStatus __last_fortnite_status: any def __init__(self, fortnite_status_observer: FortniteStatusObserver): self.__fortnite_status_observer = fortnite_status_observer self.__fortnite_status = FortniteStatus() async def run(self): # Initialize status self.__last_fortnite_status = self.__fortniteStatus.getStatus() while True: await self.__read_status() await asyncio.sleep(__polling_interval__) async def __read_status(self): service_status_tmp = self.__fortniteStatus.getStatus() if service_status_tmp != self.__last_fortnite_status: await self.__notify(service_status_tmp) self.__last_fortnite_status = service_status_tmp async def __notify(self, fortnite_status): await self.__fortnite_status_observer.update(fortnite_status)