Day 57: Get Global Weather Data with OpenWeatherMap (Module)

 

OpenWeatherMap provides free weather data for every city worldwide.

 

#Takes the name of a city and delivers
# weather data via OpenWeatherMap

import pyowm               # OpenWeatherMap-module for python

owm = pyowm.OWM('a22ec5378101af24d94fb76fexxxxx')  # You MUST provide your own API key - this one will not work

city = input("Weather forecast: (Enter City): ")


# Search for current weather in city via OWM
observation = owm.weather_at_place(city)
w = observation.get_weather()

print(city.capitalize())
# extract and print the various data
get_str = str(w)
stat = get_str.find('status') + 7
print("Condition: " + get_str[stat:-1])

tempe = w.get_temperature('celsius')

print("Celsius: " + str(tempe['temp']))

print("Humidity: " + str(w.get_humidity()))

speed = w.get_wind()

print("Wind: " + str(speed['speed']) + " kph")

Eine Antwort auf „Day 57: Get Global Weather Data with OpenWeatherMap (Module)“

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.