summaryrefslogtreecommitdiff
path: root/FortniteStatusWrapper.py
diff options
context:
space:
mode:
Diffstat (limited to 'FortniteStatusWrapper.py')
-rw-r--r--FortniteStatusWrapper.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/FortniteStatusWrapper.py b/FortniteStatusWrapper.py
index 6a80348..aa7ee12 100644
--- a/FortniteStatusWrapper.py
+++ b/FortniteStatusWrapper.py
@@ -1,5 +1,5 @@
from telebot import formatting
-import time, threading, schedule
+import time
from pythonFortniteStatus.FortniteStatus import *
__polling_interval__ = 5
@@ -7,7 +7,7 @@ __polling_interval__ = 5
fortniteStatus = FortniteStatus()
class Observer:
- def update(self, fortniteStatus) -> None:
+ async def update(self, fortniteStatus) -> None:
pass
class FortniteStatusWrapper:
@@ -15,26 +15,21 @@ 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()
- self.fortniteStatus = fortniteStatus.getStatus()
-
- def __scheduleHandler(self):
+ async def run(self):
while True:
- schedule.run_pending()
- time.sleep(1)
+ await self.__readStatus()
+ time.sleep(__polling_interval__)
- def __readStatus(self):
+ async def __readStatus(self):
serviceStatusTmp = fortniteStatus.getStatus()
if serviceStatusTmp != self.fortniteStatus:
- self.notify(serviceStatusTmp)
+ await self.__notify(serviceStatusTmp)
self.fortniteStatus = serviceStatusTmp
- def notify(self, fortniteStatus):
+ async def __notify(self, fortniteStatus):
print("Fortnite status changed, notifying observers")
for observer in self.observers:
- observer.update(fortniteStatus)
+ await observer.update(fortniteStatus)
def attach(self, observer: Observer):
self.observers.append(observer) \ No newline at end of file