Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Der-Henning
GitHub Repository: Der-Henning/tgtg
Path: blob/main/tgtg_scanner/notifiers/ifttt.py
725 views
1
import logging
2
3
from tgtg_scanner.errors import IFTTTConfigurationError, MaskConfigurationError
4
from tgtg_scanner.models import Config, Favorites, Item, Reservations
5
from tgtg_scanner.notifiers.webhook import WebHook
6
7
log = logging.getLogger("tgtg")
8
9
10
class IFTTT(WebHook):
11
"""
12
Notifier for IFTTT Webhooks.\n
13
For more information on IFTTT visit\n
14
https://ifttt.com/maker_webhooks
15
"""
16
17
def __init__(self, config: Config, reservations: Reservations, favorites: Favorites):
18
super(WebHook, self).__init__(config, reservations, favorites)
19
self.enabled = config.ifttt.enabled
20
self.event = config.ifttt.event
21
self.key = config.ifttt.key
22
self.body = config.ifttt.body
23
self.cron = config.ifttt.cron
24
self.timeout = config.ifttt.timeout
25
self.headers = {}
26
self.method = "POST"
27
self.url = f"https://maker.ifttt.com/trigger/{self.event}/with/key/{self.key}"
28
self.type = "application/json"
29
self.auth = None
30
31
if self.enabled and (not self.event or not self.key):
32
raise IFTTTConfigurationError()
33
if self.enabled and self.body is not None:
34
try:
35
Item.check_mask(self.body)
36
except MaskConfigurationError as exc:
37
raise IFTTTConfigurationError(exc.message) from exc
38
39
def __repr__(self) -> str:
40
return f"IFTTT: {self.key}"
41
42