Skip to content

Instantly share code, notes, and snippets.

@Aayush-N
Created February 8, 2018 12:17
Show Gist options
  • Save Aayush-N/dbc93620103c46b13f5301734a5e0350 to your computer and use it in GitHub Desktop.
Save Aayush-N/dbc93620103c46b13f5301734a5e0350 to your computer and use it in GitHub Desktop.
Quick Weather Data
#! python3
# quickWeather.py - Prints the weather for a location from the command line
import json, requests
location = input("Enter the location")
#Download the JSON data
url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=%s&cnt=3&APPID=<GET YOUR OWN API ID>' % (location)
response = requests.get(url)
response.raise_for_status()
#Load JSON Data into a python variable
weatherData = json.loads(response.text)
#Print weather descriptions
w = weatherData['list']
print('Curent weather in %s: ' % (location))
print(w[0]['weather'][0]['main'], '-', w[0]['weather'][0]['description'])
print()
print('Tomorrow:')
print(w[1]['weather'][0]['main'], '-', w[1]['weather'][0]['description'])
print()
print('Day after tomorrow: ')
print(w[2]['weather'][0]['main'], '-', w[2]['weather'][0]['description'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment