summaryrefslogtreecommitdiff
path: root/fortniteStatusWrapper.py
blob: 48618be7e7256291af8f61cc7da5e28c82a2415c (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
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)