-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtelegram_bot.py
44 lines (37 loc) · 1.62 KB
/
telegram_bot.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
import telebot
import time
import json
bot = telebot.TeleBot('1786817109:AAFPNlOAhqYDeL1q6ymUp0G80WKUbwhT-f0')
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row('Парковка ул. Ленина')
sleep_time = 30
from utils import get_free_from_json
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Привет, ты написал мне /start', reply_markup=keyboard1)
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() == 'парковка ул. ленина':
prev_value = -1
while(True):
value = int(get_free_from_json())
if(value==prev_value):
time.sleep(sleep_time)
continue
if(prev_value==-1):
bot.send_message(message.chat.id, "свободно {} мест".format(value))
image = open("image_1.jpg", 'rb')
bot.send_photo(message.chat.id, image)
else:
cur = value - prev_value
if cur>0:
bot.send_message(message.chat.id, "освободилось {} мест(о/а)".format(cur))
image = open("image_1.jpg", 'rb')
bot.send_photo(message.chat.id, image)
else:
bot.send_message(message.chat.id, "стало занято {} мест(о/а)".format(abs(cur)))
image = open("image_1.jpg", 'rb')
bot.send_photo(message.chat.id, image)
prev_value = value
time.sleep(sleep_time)
bot.polling()