how to read weather using python code example
Example 1: python weather api
>>> import pyowm
>>> owm = pyowm.OWM()
>>> observation = owm.weather_at_place('London,uk')
>>> w = observation.get_weather()
>>> w.get_wind()
{u'speed': 3.1, u'deg': 220}
>>> w.get_humidity()
76
Example 2: How to use open weather weather api for pytho
import requests, json
BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
URL = BASE_URL + "q=" + CITY + "&appid=" + API_KEY
response = requests.get(URL)
if response.status_code == 200:
data = response.json()
main = data['main']
temperature = main['temp']
humidity = main['humidity']
pressure = main['pressure']
report = data['weather']
print(f"{CITY:-^30}")
print(f"Temperature: {temperature}")
print(f"Humidity: {humidity}")
print(f"Pressure: {pressure}")
print(f"Weather Report: {report[0]['description']}")
else:
print("Error in the HTTP request")