-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifier.py
More file actions
41 lines (36 loc) · 1.16 KB
/
notifier.py
File metadata and controls
41 lines (36 loc) · 1.16 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
38
39
40
41
import logging
import requests
JOIN_URL = "https://joinjoaomgcd.appspot.com/_ah/api/messaging/v1/sendPush"
log = logging.getLogger(__name__)
def send_notification(
api_key: str,
device_id: str,
title: str,
author: str,
price: float,
target: float,
condition: str = "",
icon_url: str = "",
) -> bool:
cond_str = f" [{condition}]" if condition else ""
params = {
"apikey": api_key,
"deviceId": device_id,
"title": f"Bookalert: {title}",
"text": (
f"{title} by {author} is available for ${price:.2f}{cond_str} "
f"(target: ${target:.2f})"
),
}
params["icon"] = icon_url or "https://raw.githubusercontent.com/ricetim/bookalert/master/static/icon.png"
try:
resp = requests.get(JOIN_URL, params=params, timeout=10)
resp.raise_for_status()
data = resp.json()
if not data.get("success", False):
log.warning("Join API returned failure: %s", data)
return False
return True
except requests.exceptions.RequestException as e:
log.error("Failed to send Join notification: %s", e)
return False