-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbot.py
47 lines (31 loc) · 1.5 KB
/
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
import os
import telebot
from utils import get_daily_horoscope
BOT_TOKEN = os.environ.get('BOT_TOKEN')
bot = telebot.TeleBot(BOT_TOKEN)
@bot.message_handler(commands=['start', 'hello'])
def send_welcome(message):
bot.reply_to(message, "Howdy, how are you doing?")
@bot.message_handler(commands=['horoscope'])
def sign_handler(message):
text = "What's your zodiac sign?\nChoose one: *Aries*, *Taurus*, *Gemini*, *Cancer,* *Leo*, *Virgo*, *Libra*, *Scorpio*, *Sagittarius*, *Capricorn*, *Aquarius*, and *Pisces*."
sent_msg = bot.send_message(message.chat.id, text, parse_mode="Markdown")
bot.register_next_step_handler(sent_msg, day_handler)
def day_handler(message):
sign = message.text
text = "What day do you want to know?\nChoose one: *TODAY*, *TOMORROW*, *YESTERDAY*, or a date in format YYYY-MM-DD."
sent_msg = bot.send_message(
message.chat.id, text, parse_mode="Markdown")
bot.register_next_step_handler(
sent_msg, fetch_horoscope, sign.capitalize())
def fetch_horoscope(message, sign):
day = message.text
horoscope = get_daily_horoscope(sign, day)
data = horoscope["data"]
horoscope_message = f'*Horoscope:* {data["horoscope_data"]}\n*Sign:* {sign}\n*Day:* {data["date"]}'
bot.send_message(message.chat.id, "Here's your horoscope!")
bot.send_message(message.chat.id, horoscope_message, parse_mode="Markdown")
@bot.message_handler(func=lambda msg: True)
def echo_all(message):
bot.reply_to(message, message.text)
bot.infinity_polling()