-
Notifications
You must be signed in to change notification settings - Fork 0
/
pharm_bot.py
84 lines (62 loc) · 3.33 KB
/
pharm_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import logging
from time import sleep, time
import requests
import telebot
from learn_env.sergeyGit.medical_checker import Tracker
from telebot import types
from learn_env.sergeyGit.config import TOKEN_SERGEY
tracker = Tracker()
bot = telebot.TeleBot(TOKEN_SERGEY)
logger = telebot.logger
telebot.logger.setLevel(logging.DEBUG)
@bot.message_handler(commands=['start'])
def send_welcome(message):
msg = bot.send_message(message.chat.id, 'Привет! Введите название лекарства, я постараюсь найти его для Вас!')
bot.register_next_step_handler(msg, check_pharm)
def check_pharm(message):
global msg
u_choice = message.text.replace(" ","-")
if tracker.check_is_exist(u_choice) == True:
msg1 = bot.send_message(message.chat.id, 'Нашел препарат! Выберите, что конкретно хотите узнать?')
button_subustance = types.KeyboardButton(text="Состав")
button_indications = types.KeyboardButton(text="Показания")
button_anti_indications = types.KeyboardButton(text="Противопоказания")
button_method_eat = types.KeyboardButton(text="Дозировки")
button_affects = types.KeyboardButton(text="Побочные эффекты")
keyboard = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True, resize_keyboard=True)
keyboard.row(button_subustance, button_method_eat)
keyboard.row(button_indications, button_anti_indications)
keyboard.add(button_affects)
try:
msg = tracker.get_msg_bot(u_choice)
except Exception as e:
bot.send_message(message.text.id, e)
pass
bot.send_photo(message.chat.id, msg['imagelink'])
bot.register_next_step_handler(msg1, make_choice)
return tracker.make_link(u_choice)
else:
bot.send_message(message.chat.id, 'К сожалению, я не знаю такого препарата. Попробуйте найти здесь: https://tabletki.ua')
sleep(1)
abort_msg = bot.send_message(message.chat.id, 'Либо введите верное название препарата')
bot.register_next_step_handler(abort_msg, check_pharm)
def make_choice(message):
if message.text == 'Состав':
answer = bot.send_message(message.chat.id, msg['substance'][:4096])
bot.register_next_step_handler(answer, make_choice)
elif message.text == 'Показания':
answer = bot.send_message(message.chat.id, msg['indications'][:4096])
bot.register_next_step_handler(answer, make_choice)
elif message.text == 'Противопоказания':
answer = bot.send_message(message.chat.id, msg['anti_indications'][:4096])
bot.register_next_step_handler(answer, make_choice)
elif message.text == 'Дозировки':
answer = bot.send_message(message.chat.id, msg['method_eat'][:4096])
bot.register_next_step_handler(answer, make_choice)
elif message.text == 'Побочные эффекты':
answer = bot.send_message(message.chat.id, msg['affects'][:4096])
bot.register_next_step_handler(answer, make_choice)
try:
bot.polling(timeout=25)
except requests.exceptions.ConnectionError:
print('Connection error, try again please')