diff --git a/COPYING b/COPYING new file mode 100755 index 0000000..3ab62e6 --- /dev/null +++ b/COPYING @@ -0,0 +1,18 @@ +Copyright (c) 2012 Matthew Petroff + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README b/README new file mode 100755 index 0000000..71ccb31 --- /dev/null +++ b/README @@ -0,0 +1,2 @@ +From: +http://www.mpetroff.net/archives/2012/09/14/kindle-weather-display/ diff --git a/kindle/display-weather.sh b/kindle/display-weather.sh new file mode 100755 index 0000000..cfe841e --- /dev/null +++ b/kindle/display-weather.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +cd "$(dirname "$0")" + +rm weather-script-output.png +eips -c +eips -c + +if wget http://server/path/to/weather-script-output.png; then + eips -g weather-script-output.png +else + eips -g weather-image-error.png +fi diff --git a/kindle/init-weather.sh b/kindle/init-weather.sh new file mode 100755 index 0000000..13fe8fb --- /dev/null +++ b/kindle/init-weather.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +/etc/init.d/framework stop +/etc/init.d/powerd stop +/mnt/us/weather/display-weather.sh diff --git a/kindle/weather-image-error.png b/kindle/weather-image-error.png new file mode 100755 index 0000000..cd5527d Binary files /dev/null and b/kindle/weather-image-error.png differ diff --git a/server/weather-script-preprocess.svg b/server/weather-script-preprocess.svg new file mode 100755 index 0000000..a05caf4 --- /dev/null +++ b/server/weather-script-preprocess.svg @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Today: +High: +HIGH_ONE +°F +Low: +LOW_ONE +°F + +Tomorrow: +High: +HIGH_TWO +°F +Low: +LOW_TWO +°F + +DAY_THREE: +High: +HIGH_THREE +°F +Low: +LOW_THREE +°F + +DAY_FOUR: +High: +HIGH_FOUR +°F +Low: +LOW_FOUR +°F + + + + + + diff --git a/server/weather-script.py b/server/weather-script.py new file mode 100755 index 0000000..c89f807 --- /dev/null +++ b/server/weather-script.py @@ -0,0 +1,66 @@ +#!/usr/bin/python2 + +# Kindle Weather Display +# Matthew Petroff (http://www.mpetroff.net/) +# September 2012 + +import urllib2 +from xml.dom import minidom +import datetime +import codecs + + + +# +# Download and parse weather data +# + +# Fetch data (change lat and lon to desired location) +weather_xml = urllib2.urlopen('http://graphical.weather.gov/xml/SOAP_server/ndfdSOAPclientByDay.php?whichClient=NDFDgenByDay&lat=39.3286&lon=-76.6169&format=24+hourly&numDays=4&Unit=e').read() +dom = minidom.parseString(weather_xml) + +# Parse temperatures +xml_temperatures = dom.getElementsByTagName('temperature') +highs = [None]*4 +lows = [None]*4 +for item in xml_temperatures: + if item.getAttribute('type') == 'maximum': + values = item.getElementsByTagName('value') + for i in range(len(values)): + highs[i] = int(values[i].firstChild.nodeValue) + if item.getAttribute('type') == 'minimum': + values = item.getElementsByTagName('value') + for i in range(len(values)): + lows[i] = int(values[i].firstChild.nodeValue) + +# Parse icons +xml_icons = dom.getElementsByTagName('icon-link') +icons = [None]*4 +for i in range(len(xml_icons)): + icons[i] = xml_icons[i].firstChild.nodeValue.split('/')[-1].split('.')[0].rstrip('0123456789') + +# Parse dates +xml_day_one = dom.getElementsByTagName('start-valid-time')[0].firstChild.nodeValue[0:10] +day_one = datetime.datetime.strptime(xml_day_one, '%Y-%m-%d') + + + +# +# Preprocess SVG +# + +# Open SVG to process +output = codecs.open('weather-script-preprocess.svg', 'r', encoding='utf-8').read() + +# Insert icons and temperatures +output = output.replace('ICON_ONE',icons[0]).replace('ICON_TWO',icons[1]).replace('ICON_THREE',icons[2]).replace('ICON_FOUR',icons[3]) +output = output.replace('HIGH_ONE',str(highs[0])).replace('HIGH_TWO',str(highs[1])).replace('HIGH_THREE',str(highs[2])).replace('HIGH_FOUR',str(highs[3])) +output = output.replace('LOW_ONE',str(lows[0])).replace('LOW_TWO',str(lows[1])).replace('LOW_THREE',str(lows[2])).replace('LOW_FOUR',str(lows[3])) + +# Insert days of week +one_day = datetime.timedelta(days=1) +days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] +output = output.replace('DAY_THREE',days_of_week[(day_one + 2*one_day).weekday()]).replace('DAY_FOUR',days_of_week[(day_one + 3*one_day).weekday()]) + +# Write output +codecs.open('weather-script-output.svg', 'w', encoding='utf-8').write(output) diff --git a/server/weather-script.sh b/server/weather-script.sh new file mode 100755 index 0000000..5549aac --- /dev/null +++ b/server/weather-script.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +cd "$(dirname "$0")" + +python2 weather-script.py +rsvg-convert --background-color=white -o weather-script-output.png weather-script-output.svg +pngcrush -c 0 -ow weather-script-output.png +cp -f weather-script-output.png /path/to/web/server/directory/weather-script-output.png