-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather_bot2.py
More file actions
25 lines (20 loc) · 905 Bytes
/
weather_bot2.py
File metadata and controls
25 lines (20 loc) · 905 Bytes
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
import pyowm
import telebot
owm = pyowm.OWM('58e7f93e74e24c88a096481301bf4c51')
mgr = owm.weather_manager()
bot = telebot.TeleBot("5400543143:AAEDyyQmuCuGjLNg9Bq0z4kj_-2eZbuytRQ", parse_mode=None) # You can set parse_mode by default. HTML or MARKDOWN
@bot.message_handler(content_types=['text'])
def send_echo(message):
observation = mgr.weather_at_place( message.text )
w = observation.weather
temp = w.temperature('celsius')['temp']
answer = "In the city " + message.text + " now is " + w.detailed_status + "\n"
answer += "Temperature now is about " + str(temp) + " celsius" + "\n\n"
if temp < 10:
answer += "Now it`s too cold, wear the warm clothes!"
elif temp < 20:
answer += "It`s cold, don`t forget the scarf :) "
else:
answer += "So good outside :) "
bot.send_message(message.chat.id, answer)
bot.infinity_polling( none_stop = True )