S
S
slava_volkov20212022-03-31 11:30:03
Python
slava_volkov2021, 2022-03-31 11:30:03

I made a telegram bot, but unnecessary information is written at the end, how to fix it?

I decided to make a tg bot that shows the weather, but when the bot answers, it writes information about the text at the end.

import telebot
from pyowm import OWM
from pyowm.utils.config import get_default_config
import time

bot = telebot.TeleBot("TeleBot Key")
owm = OWM('API Key')

# когда вводит команду он пишит привет и имя
@bot.message_handler(commands=['start'])
def start(message):
  bot.send_message(message.chat.id, f"привет я ьот и показываю погоду /pog {message.from_user.first_name}")


@bot.message_handler(commands=['pog'])
def city(message):
  city = bot.send_message(message.chat.id, f"здравствуйте {message.from_user.first_name}, в каком вы городе: ")
  bot.register_next_step_handler(city, send_pog)

def send_pog(message):
  mgr = owm.weather_manager()

  config_dict = get_default_config()
  config_dict['language'] = 'ru'

  observation = mgr.weather_at_place(message.text)

  w = observation.weather

  named_tuple = time.localtime()
  time_string = time.strftime("%m/%d/%Y, %H:%M:%S", named_tuple)

  temp = w.temperature('celsius')["temp"]
  wind = w.wind()['speed']
  hum = w.humidity
  status = w.detailed_status

  sms = bot.send_message(message.chat.id,f"в городе {message.text} температура: {temp} \n\n влажность: {hum} \n\n скорость ветра: {wind} \n\n {status} \n\n\n   время: {time_string}")
  if temp < 10:
    ss = "прохладно "
  elif temp < 20:
    ss = "у тепло но осторожно с ветром"
  elif temp < 30:
    ss = " тепло шорты подойдут "
  elif temp < 40:
    ss = "жарок ппц"
  elif temp > 45:
    ss = "ппц жарко пойду еду погрею"
  elif temp < -10:
    ss = "прохладно надень шапку"
  elif temp < -20:
    ss = "холодно "
  elif temp < -30:
    ss = "очень холодно  осторожно"
  elif temp < -40:
    ss = "ппц холодно надень 2 ковты "
  elif temp < 45:
    ss = "ппц ..."
  else:
    ss = "чот со мной не так..."


  bot.send_message(message.chat.id, f" {sms}, {ss}")


bot.polling(none_stop=True)


624566577747c091919537.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-03-31
@SoreMix

The result of sending a message was written to the sms variable. And then sent this variable as text

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question