Answer the question
In order to leave comments, you need to log in
Bot translator. How to fix?
Wrote a small chat bot. I decided to add weather to it. Added, but it gives out the same city. How to fix it?
The code itself:
import requests
from bs4 import BeautifulSoup
class Weather:
@staticmethod
def get_weather_today(city: str = "санкт-петербург") -> list:
http = "https://sinoptik.com.ru/погода-" + city
b = BeautifulSoup(requests.get(http).text, "html.parser")
p3 = b.select('.temperature .p3')
weather1 = p3[0].getText()
p4 = b.select('.temperature .p4')
weather2 = p4[0].getText()
p5 = b.select('.temperature .p5')
weather3 = p5[0].getText()
p6 = b.select('.temperature .p6')
weather4 = p6[0].getText()
result = ''
result = result + ('Утром :' + weather1 + ' ' + weather2) + '\n'
result = result + ('Днём :' + weather3 + ' ' + weather4) + '\n'
temp = b.select('.rSide .description')
weather = temp[0].getText()
result = result + weather.strip()
return result
Answer the question
In order to leave comments, you need to log in
you need to change the conditions self._COMMAND[1] in message.upper() for example, otherwise it does not understand,
because "Weather" != "Weather Moscow"
plus pass the city parameter to the function, now it looks like it is called without passing the name of the city
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question