2 回答

TA贡献1862条经验 获得超7个赞
我不认为pywwo再有效了。我使用的是pyowm,而不是:https://pyowm.readthedocs.io/en/latest/。您将需要一个API密钥;按照这个得到一个:https://openweathermap.org/appid。
然后,您可以编写一个函数来获取温度,如下所示:
def get_temp(zipcode:str)->int:
"""function to get weather using zipcode through pyOWM
Arguments:
zipcode {str} -- given by the user
Returns:
int -- temperature in fahrenheit returned by pyOWM
for the current zipcode at the current time
"""
owm = pyowm.OWM('YOUR API KEY GOES HERE') # API key
observation = owm.weather_at_zip_code(zipcode, "us")
current_weather = observation.get_weather()
temperature = current_weather.get_temperature('fahrenheit')['temp']
return temperature
添加回答
举报