blob: 6a803487a3f586809e1329aab315e840ee12d58c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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()
self.fortniteStatus = fortniteStatus.getStatus()
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)
|