2 回答

TA貢獻1862條經驗 獲得超7個贊
我不認為pywwo再有效了。我使用的是pyowm,而不是:https://pyowm.readthedocs.io/en/latest/。您將需要一個API密鑰;按照這個得到一個:https://openweathermap.org/appid。
然后,您可以編寫一個函數(shù)來獲取溫度,如下所示:
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
添加回答
舉報