S
S
Sviche2021-07-22 20:45:00
Python
Sviche, 2021-07-22 20:45:00

How to fix the bot's telegram code so that instead of all weather information, you can display (using commands) individual weather data?

import telebot from pyowm.owm
; import OWM
from pyowm.utils.config ; (message.chat.id, 'Welcome, I'm a bot that knows the weather around the world' + '\n' + 'To find out the weather, write the name of any city in the chat\n/help - all bot commands') @bot.message_handler( commands=['help']) def help(message): bot.send_message(message.chat.id, '/start - start bot\n/help - bot commands\nType city name in chat for weather info') @bot.message_handler(content_types=['text'])


def test(message):
try:
place = message.text
config_dict = get_default_config()
config_dict['language'] = 'ru'
owm = OWM('08773350d0b54db244c618030a729ab6', config_dict)
mgr = owm.weather_manager()
observation = mgr.weather_at_place (place)
w = observation.weather
t = w.temperature('celsius')
t1 = t['temp']
t2 = t['feels_like']
t3 = t['temp_max']
t4 = t['temp_min']

wi = w.wind()['speed']
humi = w.humidity
cl = w.clouds
dt = w.detailed_status
ti = w.reference_time('iso')
pr = w.pressure['press']
vd = w.visibility_distance
st = w.status

bot.send_message(message.chat.id, 'In town ' + str(place) + ' temperature ' + str(t1) + ' C' + '\n' +
' Maximum temperature ' + str(t3) + 'C' + '\n'+
' Minimum temperature ' + str(t4) + 'C' + '\n' +
'Feels like ' + str(t2) + 'C' + '\n' +
'Wind speed ' + str(wi) + 'm/s' + '\n' +
'Pressure ' + str(pr) + 'mmHg'+ '\n' +
'Humidity ' + str(humi) + '%' + '\n' +
'Visibility ' + str(vd) + 'meters' + '\n'
'Status ' + str(st) + '\n' + str(dt) )

except:
bot.send_message(message.chat.id, ' Such city ​​not found')
print(str(message.text), '- not found')
bot.polling(none_stop=True, interval=0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2021-07-23
@trapwalker

1. Add new commands.
2. Display partial data on them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question