· 4 years ago · Apr 06, 2021, 09:28 AM
1import telebot
2from telebot import types
3from pyowm import OWM
4from pycbrf import ExchangeRates
5from datetime import datetime
6
7TOKEN = 'My API key'
8bot = telebot.TeleBot(TOKEN)
9
10owm = OWM('My API key')
11
12
13@bot.message_handler(commands=['twitter']) # Twitter command which gives you link
14def open_twitter(message):
15 markup = types.InlineKeyboardMarkup()
16 markup.add(types.InlineKeyboardButton("Click here", url='https://twitter.com/isakhanian96', ))
17 bot.send_message(message.chat.id, "Here is my twitter blog. Check it out!", parse_mode='html',
18 reply_markup=markup)
19
20
21@bot.message_handler(commands=['resume']) # Resume command which gives you link
22def open_resume(message):
23 markup = types.InlineKeyboardMarkup()
24 markup.add(types.InlineKeyboardButton("Click here", url='https://hh.ru/resume'
25 '/fd285f17ff08d152da0039ed1f446554323463', ))
26 bot.send_message(message.chat.id, "Resume of a Junior Python Developer", parse_mode='html',
27 reply_markup=markup)
28
29
30@bot.message_handler(commands=['github']) # GitHub command which gives you link
31def open_github(message):
32 markup = types.InlineKeyboardMarkup()
33 markup.add(types.InlineKeyboardButton("Click here", url='https://github.com/Temik26?tab=repositories'))
34 bot.send_message(message.chat.id, "GitHub account. You can check my projects soon, stay tune", parse_mode='html',
35 reply_markup=markup)
36
37
38@bot.message_handler(commands=['start'])
39def start(message):
40 markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
41 k1 = types.KeyboardButton("USD")
42 k2 = types.KeyboardButton("EUR")
43 k3 = types.KeyboardButton("Twitter")
44 k4 = types.KeyboardButton("Resume")
45 k5 = types.KeyboardButton("GitHub")
46 markup.add(k1, k2, k3, k4, k5)
47 bot.send_message(message.chat.id,
48 f"Hi,{message.from_user.first_name}! Nice to see you here! Thanks for using this bot. There are "
49 f"some buttons under "
50 f"message field, just click the one you like or use any command down below.\n "
51 f"\n/twitter — Twitter blog\n/resume — Junior Python Developer resume \n/github — GitHub account "
52 f"(no projects yet) \n\nTo get list of available commands use /commands",
53 parse_mode='html', reply_markup=markup)
54
55
56@bot.message_handler(commands=['commands'])
57def show_all_commands(message):
58 bot.send_message(message.chat.id,
59 f"{message.from_user.first_name}, here are available commands \n\n/twitter\n/resume\n/github")
60
61
62@bot.message_handler(content_types=['text'])
63def gives_links(message):
64 button1 = types.InlineKeyboardMarkup()
65 button2 = types.InlineKeyboardMarkup()
66 button3 = types.InlineKeyboardMarkup()
67 button1.add(types.InlineKeyboardButton("Click here", url='https://twitter.com/isakhanian96', ))
68 button2.add(types.InlineKeyboardButton("Click here", url='https://hh.ru/resume'
69 '/fd285f17ff08d152da0039ed1f446554323463', ))
70 button3.add(types.InlineKeyboardButton("Click here", url='https://github.com/Temik26?tab=repositories', ))
71 message_norm = message.text.strip().lower()
72 if message.text == "Twitter":
73 bot.send_message(message.chat.id, 'Here is my twitter blog. Check it out!', reply_markup=button1)
74 elif message.text == "Resume":
75 bot.send_message(message.chat.id, 'Resume of a Junior Python Developer',
76 reply_markup=button2)
77 elif message.text == "GitHub":
78 bot.send_message(message.chat.id,
79 "Here is my GitHub account. I don't have any projects, but I'll get one done soon, stay tune!",
80 reply_markup=button3)
81 elif message_norm in ['usd', 'eur']:
82 rates = ExchangeRates(datetime.now())
83 bot.send_message(message.chat.id,
84 f'Today is {datetime.now().strftime("%A, %B %d, %Y").lstrip("0").replace(" 0", " ")} '
85 f'\n{message_norm.upper()} rate — {float(rates[message_norm.upper()].rate)} ₽',
86 parse_mode='html')
87
88
89# @bot.message_handler(func=lambda m: True) # Shows the weather (doesn't work properly for now)
90# def echo_all(message):
91# mgr = owm.weather_manager()
92# observation = mgr.weather_at_place(message.text)
93# w = observation.weather
94# weather_info = "Weather in " + message.text + " " "\n" "Temperature: " + str(
95# round(w.temperature('celsius')['temp'])) + "°C" + "\n" + "Wind speed: " + str(
96# w.wind()['speed']) + " m/s" + "\n" + "Humidity: " + str(w.humidity)
97# bot.reply_to(message, weather_info)
98
99
100bot.polling()
101