DEV Community

Senthil Pitchappan V
Senthil Pitchappan V

Posted on • Edited on

WEATHER API IN 6 LINES OF CODE

This can be used in any application with minimum lines of code. I guess this is the best Weather API you will find on the internet. Easy to use and Opensource.

To get API Key

  1. Go to Open Weather
  2. Sign in / Sign up to your account
  3. Go to API Key Page
  4. Give your API Key a name, and click generate.
import requests
api_address='http://api.openweathermap.org/data/2.5/weather?appid=YOUR_API_KEY&q='
city = input('City Name :')
url = api_address + city
json_data = requests.get(url).json()
print(json_data)

formatted_data = json_data['weather'][0]['main']
print(formatted_data)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)