-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfor_ga.py
More file actions
26 lines (21 loc) · 766 Bytes
/
for_ga.py
File metadata and controls
26 lines (21 loc) · 766 Bytes
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
import os
import requests
import checker
NICKNAMES = os.environ.get("NICKNAMES")
TELEGRAM_BOT_TOKEN = os.environ.get("TELEGRAM_BOT_TOKEN")
TELEGRAM_CHAT_ID = os.environ.get("TELEGRAM_CHAT_ID")
if not all({NICKNAMES, TELEGRAM_BOT_TOKEN, TELEGRAM_CHAT_ID}):
raise RuntimeError(
"You need to set NICKNAMES, "
"TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID "
"environment variables"
)
for nickname in NICKNAMES.split(","):
if checker.check(nickname):
url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage"
data = {
"chat_id": TELEGRAM_CHAT_ID,
"text": f"<code>{nickname}</code> is available now!",
"parse_mode": "HTML",
}
requests.post(url, json=data)