-
Notifications
You must be signed in to change notification settings - Fork 0
/
radio_pinger.py
executable file
·64 lines (47 loc) · 1.9 KB
/
radio_pinger.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python2.7
# coding: utf8
import sys
import random
import telegram
from consts import *
from stream_status import check_stream
SLEEP_SECONDS = 60 * 5
def reply_sticker(sticker_id):
bot.send_sticker(chat_id=fradio_chat_id, sticker=sticker_id)
def reply_text(text):
bot.send_message(chat_id=fradio_chat_id, text=text)
def reply_broken_radio():
actions = [
lambda: reply_text(
"Походу, радио сдохло! Проверьте: http://radio.mipt.ru"),
lambda: reply_text(
"@mierokhin, радио кажись сделало сибастиена из эфира! Разберись с этим: http://radio.mipt.ru"),
lambda: reply_text(
"@Exferro, радио из дэд. Разберись с этим: http://radio.mipt.ru"),
lambda: reply_text(
"@ivanpotylitcyn, радио из дэад. Разберись с этим: http://radio.mipt.ru"),
lambda: reply_sticker(broken_radio_sticker1),
lambda: (reply_text("не работает http://radio.mipt.ru"),
reply_sticker(broken_radio_sticker2)),
lambda: (reply_text("радио не работает"),
reply_sticker(broken_radio_sticker3)),
lambda: (reply_text("радио не работает :С :С :С"),
reply_sticker(broken_radio_sticker2))
]
random.choice(actions)()
if len(sys.argv) < 2:
print("Need Telegram bot token")
exit()
token = sys.argv[1]
with open(fizteh_chat_id_path, "r") as file:
fradio_chat_id = file.read().strip()
print("FIZTEH RADIO token is /" + fradio_chat_id + "/")
# with open(bot_token, "r") as f:
# token = f.read().strip()
bot = telegram.Bot(token)
print("Started bot with token /" + token + "/")
while True:
is_alive = check_stream()
if not is_alive:
reply_broken_radio()
time.sleep(SLEEP_SECONDS)