Weather Forecast V1 (Python)

Last night and this morning has seen a little bit of snow across Manchester (UK), spurring me on to create my weather checker in Python.

I am making use of the open API that http://openweathermap.org provides and having signed up for a free API key I’ve got straight into creating a Python program.

open weather json

Things to do:

– Get it to ask for user location input as Open Weather Map can search on locations

– Get it to display a small graphic (e.g. snow flakes) for the first forecast

– Get it to ask user for how many forecasts they want to see (e.g. 3 instead of 10, this would cover a 9hr window of weather)

——————

#!/bin/python3

#geektechstuff

#print weather location for Manchester, UK

#imports required modules

import json, requests

#calls on the API of openweathermap.org

#ID is for Manchester, see http://openweathermap.org/api for an APPID(API KEY)

url=’http://api.openweathermap.org/data/2.5/forecast?id=3333169&APPID=XXXXXXXXX’

response=requests.get(url)

response.raise_for_status()

#Loads the JSON

weatherData=json.loads(response.text)

w=weatherData[‘list’]

print(“Weather for Manchester, UK”)

print(”)

#Cycles through the next 10 3hr blocks which is roughly the next 30hrs

weather=range(0,10)

for x in weather:

    print(w[x][‘dt_txt’])

    print(w[x][‘weather’][0][‘main’],’-‘,w[x][‘weather’][0][‘description’])

    #Converts F into C, as I’m more of a celsius person

    temp_c=w[x][‘main’][‘temp’]

    temp_c=float(temp_c)

    temp_c=temp_c/32

    print(‘Average temp in Celsius:’,temp_c)

    x=x+1

    print(”)    

One thought on “Weather Forecast V1 (Python)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.