Answer the question
In order to leave comments, you need to log in
How to change language in PyOwm?
The language does not change in pyowm, I take the key from OpenWeather, I had to do it through a translator, how to fix it?
owm = pyowm.OWM('ключ из openweaher', language = "RU") # тут пробовал и ru, все равно английский
observation = owm.weather_at_place(city)
w = observation.get_weather()
temperature = w.get_temperature('celsius')['temp']
translator= Translator(from_lang="english",to_lang="russian")
self.write_msg(id, "В городе " + city.title() + " " + str(math.ceil(temperature)) + "°. " + "Вижу: " + translator.translate(w.get_status()))
Answer the question
In order to leave comments, you need to log in
I read some documentation and made the translation in this way :)
from pyowm import OWM
from pyowm.utils.config import get_default_config
place = input(" Введите город/страну: ")
config_dict = get_default_config()
config_dict['language'] = 'ru'
owm = OWM( 'API-Key', config_dict )
mgr = owm.weather_manager()
observation = mgr.weather_at_place(place)
w = observation.weather
print(w)
Actual for version PyOWM 3.0.0
import pyowm
from pyowm.commons.enums import SubscriptionTypeEnum
from pyowm.utils.measurables import kelvin_to_celsius
city = 'Moscow'
config = {
'subscription_type': SubscriptionTypeEnum.FREE,
'language': 'ru',
'connection': {
'use_ssl': True,
'verify_ssl_certs': True,
'use_proxy': False,
'timeout_secs': 5
},
'proxies': {
'http': 'http://user:[email protected]:port',
'https': 'socks5://user:[email protected]:port'
}
}
owm = pyowm.OWM('', config=config)
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
print("В городе " + city + " сейчас температура: " + str(kelvin_to_celsius(w.temp['temp'])) + " по Цельсию.")
print('Погода в указанном городе: ' + observation.location.name)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question