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