-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.py
More file actions
36 lines (27 loc) · 943 Bytes
/
background.py
File metadata and controls
36 lines (27 loc) · 943 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
27
28
29
30
31
32
33
34
35
36
import os
import time
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"
)
def main():
while True:
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)
time.sleep(60)
if __name__ == "__main__":
main()