-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbmmbackend.py
More file actions
37 lines (29 loc) · 1.13 KB
/
bmmbackend.py
File metadata and controls
37 lines (29 loc) · 1.13 KB
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
import requests
import logging
class bmmbackend:
def __init__(self, backendURL, generatorID) -> None:
if backendURL.endswith('/'):
self.backendURL = backendURL[:-1]
else:
self.backendURL = backendURL
self.generatorID = generatorID
def getEvents(self, api_key):
try:
response = requests.get(f"{self.backendURL}/api/events/bygenerator/{self.generatorID}?api_key={api_key}")
response = response.json()
return response
except Exception as e:
logging.exception('Az eseményeket nem tudom lekérdezni a backendtől.')
raise e
def notifyEvent(self, eventUUID, content, api_key):
notificationData = {
'uuid': self.generatorID,
'eventUuid': eventUUID,
'content': content
}
try:
response = requests.post(f"{self.backendURL}/api/events/notify/{eventUUID}?api_key={api_key}", data=notificationData)
return response
except Exception as e:
logging.exception('A backend értesítése nem sikerült.')
raise e