Get weather data for your location

Find more about Weather in Altendorf, SW
Click for weather forecast

If you have no own weather station but are interested in local weather data then weather data from Weather Underground  (wunderground) can help to close this gap.

I built three small scripts to ask wunderground for data, send the to the thingspeak server for visualization and cover both scripts. You will find them on Github for download.

wunderweather.py asks Wunderground for locale weather data. Local means here Altendorf in Switzerland.

#!/usr/bin/python

# Reading weather data from wunderground network

import urllib2
import json

f = urllib2.urlopen('http://api.wunderground.com/api/a50aba1a6119706f/geolookup/conditions/q/Switzerland/Altendorf.json')
json_string = f.read()
parsed_json = json.loads(json_string)

location = parsed_json['location']['city']
temp_c = parsed_json['current_observation']['temp_c']
rel_hum = parsed_json['current_observation']['relative_humidity']
weather = parsed_json['current_observation']['weather']
station = parsed_json['current_observation']['station_id']
updated = parsed_json['current_observation']['observation_time_rfc822']
print("Current temperature in %s is: %s *C" % (location, temp_c))
print("Current relative humidity is: %s %%" % (rel_hum))
print("Weather is %s " % (weather))
print("Weather station is %s" % (station))
print("Last updated: %s" % (updated))

f.close()

f = open("TEMP","w")
f.write(str(temp_c))
f.close()

f = open("HUMI","w")
f.write(str(rel_hum))
f.close()

thingspeak.sh sends temperature und humidity to the Thingspeak server:

#!/bin/sh

echo "Send data to Thingspeak Server"

#Thingspeak
 api_key='CRPX6X538QZ1DZHY'

DATE=date
read TEMP < /home/TEMP
echo "Temperature = $TEMP *C"
read HUMI < /home/HUMI     echo "Rel. Humidity = $HUMI %"     curl --data \       "api_key=$api_key&field1=$TEMP&field2=$HUMI&field3=$DATE" \       https://api.thingspeak.com/update > log 2>&1

As you can see from both scripts you need access data for the APIs. Therefore you have to register on both services.

The last script weather.sh covers both calls. That’s all:

#!/bin/sh

/home/wunderweather.py
/home/thingspeak.sh
echo "Done."

Temperature Graph

Humidity Graph

 

Advertisements
Get weather data for your location

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s