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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# Simple utility class which provides an access to Fortnite service status report.
# Usage: ForniteStatus().getStatus()
import requests as req
import html5lib
from bs4 import BeautifulSoup
# Polling interval in seconds
__polling_interval__ = 5 * 60 # 5 minutes
class FortniteStatusObserver:
async def update(self, fortnite_status) -> None:
pass
class FortniteStatus:
"""
Instantiate a FortniteStatus class.
"""
class Status:
serviceStatuses = []
def __init__(self, serviceStatuses):
self.serviceStatuses = serviceStatuses
def __eq__(self, other):
if not isinstance(other, FortniteStatus.Status):
return NotImplemented
return sorted(self.serviceStatuses) == sorted(other.serviceStatuses)
def prettify(self):
return 'Fortnite services status:\n' + '\n'.join([serviceStatus.prettify() for serviceStatus in self.serviceStatuses])
class ServiceStatus:
serviceName = ''
status = False
def __init__(self, serviceName, status):
self.serviceName = serviceName
self.status = status
def __lt__(self, other):
if not isinstance(other, FortniteStatus.ServiceStatus):
return NotImplemented
return self.serviceName < other.serviceName
def __eq__(self, other):
if not isinstance(other, FortniteStatus.ServiceStatus):
return NotImplemented
return self.serviceName == other.serviceName and self.status == other.status
def prettify(self):
return f'{self.serviceName}, {self.status}'
def __findFortniteStatusHtmlComponent(self, html):
for component in html.findAll('div', {'class': 'component-container'}):
innerContainers = component.findAll('div', {'class': 'component-inner-container'})
for innerContainer in innerContainers:
for names in innerContainer.findAll('span', {'class': 'name'}):
for name in names.findAll('span'):
if 'class' not in name.attrs and 'Fortnite' in name.text:
return component
def __parseFortniteStatus(self, html):
component = self.__findFortniteStatusHtmlComponent(html)
serviceStatuses = []
childContainer = component.find('div', {'class': 'child-components-container'})
for innerContainer in childContainer.findAll('div', {'class': 'component-inner-container'}):
name = innerContainer.find('span', {'class': 'name'}).text.strip()
statusString = innerContainer.find('span', {'class': 'component-status'}).text.strip()
if statusString == 'Operational':
statusCode = True
else:
statusCode = False
serviceStatuses.append(self.ServiceStatus(name, statusCode))
return self.Status(serviceStatuses)
def getStatus(self):
webContent = req.get("https://status.epicgames.com/")
parsedHtml = BeautifulSoup(webContent.text, 'html5lib')
return self.__parseFortniteStatus(parsedHtml)
def printStatus(self):
"""
Prints a current Fortnite services status in stdout.
Example:
"""
print(self.getStatus().prettify())
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.__fortnite_status.getStatus()
while True:
await self.__read_status()
await asyncio.sleep(__polling_interval__)
async def __read_status(self):
service_status_tmp = self.__fortnite_status.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)
|