DEV Community

loading...

WEATHER API IN 6 LINES OF CODE

Senthil Pitchappan V
I depend upon my skills rather than my curriculam. I write software programs way beyond the classes I have taken and I think I have got better over time.
Updated on ・1 min read

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

Discussion (0)