├── .gitignore ├── extras └── README.md ├── server ├── assets │ ├── 0.png │ ├── 1.png │ ├── 2.png │ ├── 3.png │ ├── 4.png │ ├── 5.png │ ├── 6.png │ ├── 7.png │ ├── 8.png │ ├── 9.png │ ├── 10.png │ ├── 11.png │ ├── 12.png │ ├── 13.png │ ├── 14.png │ ├── 15.png │ ├── 16.png │ ├── 17.png │ ├── 18.png │ ├── 19.png │ ├── 20.png │ ├── 21.png │ ├── 22.png │ ├── 23.png │ ├── 24.png │ ├── 25.png │ ├── 26.png │ ├── 27.png │ ├── 28.png │ ├── 29.png │ ├── 30.png │ ├── 31.png │ ├── 32.png │ ├── 33.png │ ├── 34.png │ ├── 35.png │ ├── 36.png │ ├── 37.png │ ├── 38.png │ ├── 39.png │ ├── 40.png │ ├── 41.png │ ├── 42.png │ ├── 43.png │ ├── 44.png │ ├── 45.png │ ├── 46.png │ ├── 47.png │ ├── na.png │ ├── 12__.png │ ├── 21__.png │ ├── 22__.png │ ├── 35__.png │ ├── 39__.png │ ├── 41__.png │ ├── 44__.png │ ├── 45__.png │ ├── 46__.png │ └── 47__.png ├── launch.sh ├── template.svg ├── parse_weather_old.py └── parse_weather.py ├── kindleweatherfiles.zip ├── weather-script-output.png ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /extras/README.md: -------------------------------------------------------------------------------- 1 | Extra files 2 | -------------------------------------------------------------------------------- /server/assets/0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/0.png -------------------------------------------------------------------------------- /server/assets/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/1.png -------------------------------------------------------------------------------- /server/assets/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/2.png -------------------------------------------------------------------------------- /server/assets/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/3.png -------------------------------------------------------------------------------- /server/assets/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/4.png -------------------------------------------------------------------------------- /server/assets/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/5.png -------------------------------------------------------------------------------- /server/assets/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/6.png -------------------------------------------------------------------------------- /server/assets/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/7.png -------------------------------------------------------------------------------- /server/assets/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/8.png -------------------------------------------------------------------------------- /server/assets/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/9.png -------------------------------------------------------------------------------- /server/assets/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/10.png -------------------------------------------------------------------------------- /server/assets/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/11.png -------------------------------------------------------------------------------- /server/assets/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/12.png -------------------------------------------------------------------------------- /server/assets/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/13.png -------------------------------------------------------------------------------- /server/assets/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/14.png -------------------------------------------------------------------------------- /server/assets/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/15.png -------------------------------------------------------------------------------- /server/assets/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/16.png -------------------------------------------------------------------------------- /server/assets/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/17.png -------------------------------------------------------------------------------- /server/assets/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/18.png -------------------------------------------------------------------------------- /server/assets/19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/19.png -------------------------------------------------------------------------------- /server/assets/20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/20.png -------------------------------------------------------------------------------- /server/assets/21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/21.png -------------------------------------------------------------------------------- /server/assets/22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/22.png -------------------------------------------------------------------------------- /server/assets/23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/23.png -------------------------------------------------------------------------------- /server/assets/24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/24.png -------------------------------------------------------------------------------- /server/assets/25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/25.png -------------------------------------------------------------------------------- /server/assets/26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/26.png -------------------------------------------------------------------------------- /server/assets/27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/27.png -------------------------------------------------------------------------------- /server/assets/28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/28.png -------------------------------------------------------------------------------- /server/assets/29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/29.png -------------------------------------------------------------------------------- /server/assets/30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/30.png -------------------------------------------------------------------------------- /server/assets/31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/31.png -------------------------------------------------------------------------------- /server/assets/32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/32.png -------------------------------------------------------------------------------- /server/assets/33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/33.png -------------------------------------------------------------------------------- /server/assets/34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/34.png -------------------------------------------------------------------------------- /server/assets/35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/35.png -------------------------------------------------------------------------------- /server/assets/36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/36.png -------------------------------------------------------------------------------- /server/assets/37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/37.png -------------------------------------------------------------------------------- /server/assets/38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/38.png -------------------------------------------------------------------------------- /server/assets/39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/39.png -------------------------------------------------------------------------------- /server/assets/40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/40.png -------------------------------------------------------------------------------- /server/assets/41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/41.png -------------------------------------------------------------------------------- /server/assets/42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/42.png -------------------------------------------------------------------------------- /server/assets/43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/43.png -------------------------------------------------------------------------------- /server/assets/44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/44.png -------------------------------------------------------------------------------- /server/assets/45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/45.png -------------------------------------------------------------------------------- /server/assets/46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/46.png -------------------------------------------------------------------------------- /server/assets/47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/47.png -------------------------------------------------------------------------------- /server/assets/na.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/na.png -------------------------------------------------------------------------------- /kindleweatherfiles.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/kindleweatherfiles.zip -------------------------------------------------------------------------------- /server/assets/12__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/12__.png -------------------------------------------------------------------------------- /server/assets/21__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/21__.png -------------------------------------------------------------------------------- /server/assets/22__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/22__.png -------------------------------------------------------------------------------- /server/assets/35__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/35__.png -------------------------------------------------------------------------------- /server/assets/39__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/39__.png -------------------------------------------------------------------------------- /server/assets/41__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/41__.png -------------------------------------------------------------------------------- /server/assets/44__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/44__.png -------------------------------------------------------------------------------- /server/assets/45__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/45__.png -------------------------------------------------------------------------------- /server/assets/46__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/46__.png -------------------------------------------------------------------------------- /server/assets/47__.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/server/assets/47__.png -------------------------------------------------------------------------------- /weather-script-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yoonsikp/weather-display/HEAD/weather-script-output.png -------------------------------------------------------------------------------- /server/launch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd "$(dirname "$0")" 4 | 5 | #Parse Weather and replace placeholder text in the svg template file 6 | python parse_weather.py 7 | 8 | #convert svg to png, and rotate 90 degrees for horizontal view 9 | convert -depth 8 -rotate 90 weather-processed.svg weather-processed.png 10 | 11 | #We optimize the image (necessary for viewing on the kindle) 12 | pngcrush -q -c 0 weather-processed.png weather-script-output.png > /dev/null 2>&1 13 | 14 | #We move the image where it needs to be (the webserver directory) 15 | rm /var/www/weather-script-output.png 16 | mv weather-script-output.png /var/www/weather-script-output.png 17 | 18 | #garbage cleanup 19 | rm weather-processed.svg 20 | rm weather-processed.png 21 | 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 yoonsikp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # weather-display 2 | A customizable script to display Yahoo weather data as a portable image. 3 | ![alt text](https://raw.githubusercontent.com/yoonsikp/weather-display/master/weather-script-output.png "Logo Title Text 1") 4 | 5 | ## Server Installation 6 | First, install DejaVu Fonts. 7 | 8 | Next install imagemagick and pngcrush. 9 | ``` 10 | apt-get install imagemagick pngcrush 11 | ``` 12 | Configure imagemagick so that it can find the DejaVu fonts. 13 | 14 | Then use pip to install the required dependencies. 15 | ``` 16 | pip install myql dom 17 | ``` 18 | Insert the script `launch.sh` into your crontab. 19 | 20 | Finally, install the web server of your choice and allow the port through your firewall. 21 | 22 | ## Client Installation 23 | Unzip the contents of `kindleweatherfiles.zip` into the root directory of your Kindle. 24 | Install the jailbreak, and USBNetworking. 25 | 26 | Finally, add `/mnt/us/weather/display-weather.sh` to the cron file on the Kindle. 27 | 28 | ## Troubleshooting 29 | if imagemagick can't find your fonts: 30 | Copy fonts to a directory of your choice 31 | 32 | Determine the directory of your imagemagick configuration type.xml 33 | 34 | In my case, it was `/usr/local/Cellar/imagemagick/6.9.7-0/etc/ImageMagick-6` 35 | ``` 36 | cd /usr/local/Cellar/imagemagick/6.9.7-0/etc/ImageMagick-6 37 | 38 | wget http://www.imagemagick.org/Usage/scripts/imagick_type_gen -O script.pl 39 | 40 | find /Users/username/your_font_directory -name '*Deja*' |./script.pl -f - > ./type-morefonts.xml 41 | ``` 42 | Finally edit `type.xml` 43 | ``` 44 | nano type.xml 45 | ``` 46 | Near the end of the file between `` and ``, add `` 47 | 48 | -------------------------------------------------------------------------------- /server/template.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Weather 6 | 7 | UNIT 8 | TODAY 9 | CITY 10 | As of TIME 11 | STATUS 12 | NESW 13 | Sunrise: 14 | Sunset: 15 | SUNRISE 16 | SUNSET 17 | SPEED 18 | HUMID 19 | Humidity: 20 | % 21 | Wind: 22 | 23 | LOW_ONE 24 | ° 25 | Feels Like: 26 | 27 | HIGH_ONE° 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /server/parse_weather_old.py: -------------------------------------------------------------------------------- 1 | import urllib2 2 | from xml.dom import minidom 3 | import datetime 4 | import codecs 5 | 6 | def getCardinal(angle): 7 | directions = 8 8 | degree = 360 / directions 9 | angle = angle + degree/2 10 | if angle >= (0 * degree) and angle < (1 * degree): 11 | return "N" 12 | if angle >= (1 * degree) and angle < (2 * degree): 13 | return "NE" 14 | if angle >= (2 * degree) and angle < (3 * degree): 15 | return "E" 16 | if angle >= (3 * degree) and angle < (4 * degree): 17 | return "SE" 18 | if angle >= (4 * degree) and angle < (5 * degree): 19 | return "S" 20 | if angle >= (5 * degree) and angle < (6 * degree): 21 | return "SW" 22 | if angle >= (6 * degree) and angle < (7 * degree): 23 | return "W" 24 | if angle >= (7 * degree) and angle < (8 * degree): 25 | return "NW" 26 | return "N" 27 | 28 | #Code of my city 29 | CODE = "2972" 30 | #Change to false if you want Fahrenheit and mph 31 | METRIC = True 32 | if METRIC: 33 | weather_xml = urllib2.urlopen('http://weather.yahooapis.com/forecastrss?w=' + CODE + '&u=c&d=9').read() 34 | else: 35 | weather_xml = urllib2.urlopen('http://weather.yahooapis.com/forecastrss?w=' + CODE + '&u=f&d=9').read() 36 | 37 | dom = minidom.parseString(weather_xml) 38 | 39 | #Get weather Tags 40 | xml_current = dom.getElementsByTagName('yweather:condition') 41 | xml_temperatures = dom.getElementsByTagName('yweather:forecast') 42 | xml_wind = dom.getElementsByTagName('yweather:wind') 43 | xml_location = dom.getElementsByTagName('yweather:location') 44 | xml_atmos = dom.getElementsByTagName('yweather:atmosphere') 45 | xml_units = dom.getElementsByTagName('yweather:units') 46 | xml_astron = dom.getElementsByTagName('yweather:astronomy') 47 | #Get today Tag 48 | current = xml_current[0] 49 | today = xml_temperatures[4] 50 | wind = xml_wind[0] 51 | location = xml_location[0] 52 | atmos = xml_atmos[0] 53 | units = xml_units[0] 54 | astron = xml_astron[0] 55 | #Get info 56 | status = current.getAttribute('text') 57 | image = current.getAttribute('code') 58 | date = current.getAttribute('date') 59 | concisedates = date.split() 60 | concisedate = ' '.join([concisedates[2],concisedates[1].lstrip("0")]) 61 | concisetime = ' '.join([concisedates[4],concisedates[5]]) 62 | 63 | temp = current.getAttribute('temp') 64 | low = today.getAttribute('low') 65 | high = today.getAttribute('high') 66 | chill = wind.getAttribute('chill') 67 | direction = wind.getAttribute('direction') 68 | speed = wind.getAttribute('speed') 69 | humidity = atmos.getAttribute('humidity') 70 | pressure = atmos.getAttribute('pressure') 71 | pressureunit = units.getAttribute('pressure') 72 | city = location.getAttribute('city') 73 | sunset = astron.getAttribute('sunset') 74 | sunrise = astron.getAttribute('sunrise') 75 | image_url = 'assets/' + image + '.png' 76 | 77 | # Open SVG to process 78 | output = codecs.open('template.svg', 'r', encoding='utf-8').read() 79 | 80 | 81 | # Insert icons and temperatures 82 | output = output.replace('TODAY',concisedate) 83 | output = output.replace('TIME',concisetime) 84 | output = output.replace('CITY',city) 85 | output = output.replace('HUMID',humidity) 86 | output = output.replace('ICON_ONE',image_url) 87 | output = output.replace('HIGH_ONE',temp) 88 | 89 | output = output.replace('LOW_ONE',chill) 90 | output = output.replace('SUNSET',sunset.rstrip(' pm')) 91 | output = output.replace('SUNRISE',sunrise.rstrip(' am')) 92 | 93 | output = output.replace('STATUS',status) 94 | if chill==temp: 95 | output = output.replace('black','white') 96 | output = output.replace('TEMPYCOORD','310') 97 | else: 98 | output = output.replace('TEMPYCOORD','270') 99 | 100 | 101 | output = output.replace('SPEED',str(int(round(float(speed))))) 102 | output = output.replace('NESW',getCardinal(float(direction))) 103 | if METRIC: 104 | output = output.replace('UNIT','km/h') 105 | else: 106 | output = output.replace('UNIT','mph') 107 | # Write output 108 | codecs.open('weather-processed.svg', 'w', encoding='utf-8').write(output) 109 | -------------------------------------------------------------------------------- /server/parse_weather.py: -------------------------------------------------------------------------------- 1 | import myql 2 | import urllib2 3 | from xml.dom import minidom 4 | import datetime 5 | import codecs 6 | def getCardinal(angle): 7 | directions = 8 8 | degree = 360 / directions 9 | angle = angle + degree/2 10 | if angle >= (0 * degree) and angle < (1 * degree): 11 | return "N" 12 | if angle >= (1 * degree) and angle < (2 * degree): 13 | return "NE" 14 | if angle >= (2 * degree) and angle < (3 * degree): 15 | return "E" 16 | if angle >= (3 * degree) and angle < (4 * degree): 17 | return "SE" 18 | if angle >= (4 * degree) and angle < (5 * degree): 19 | return "S" 20 | if angle >= (5 * degree) and angle < (6 * degree): 21 | return "SW" 22 | if angle >= (6 * degree) and angle < (7 * degree): 23 | return "W" 24 | if angle >= (7 * degree) and angle < (8 * degree): 25 | return "NW" 26 | return "N" 27 | 28 | #Code of my city 29 | CODE = "2972" 30 | #Change to false if you want Fahrenheit and mph 31 | METRIC = True 32 | 33 | from myql.utils import pretty_json, pretty_xml 34 | yql = myql.MYQL(format='xml', community=True) 35 | 36 | #can't trust windchill if specified in celsius (must parse from fahrenheit) 37 | weather_xml = yql.raw_query('select * from weather.forecast where woeid = ' + CODE + ' and u ="f"') 38 | dom = minidom.parseString(weather_xml.content) 39 | xml_wind = dom.getElementsByTagName('yweather:wind') 40 | wind = xml_wind[0] 41 | chill = wind.getAttribute('chill') 42 | 43 | 44 | if METRIC: 45 | weather_xml = yql.raw_query('select * from weather.forecast where woeid = ' + CODE + ' and u ="c"') 46 | chill = str(int(round((float(chill) - 32) / 1.8))) 47 | dom = minidom.parseString(weather_xml.content) 48 | 49 | #Get weather Tags 50 | xml_current = dom.getElementsByTagName('yweather:condition') 51 | xml_temperatures = dom.getElementsByTagName('yweather:forecast') 52 | xml_wind = dom.getElementsByTagName('yweather:wind') 53 | xml_location = dom.getElementsByTagName('yweather:location') 54 | xml_atmos = dom.getElementsByTagName('yweather:atmosphere') 55 | xml_units = dom.getElementsByTagName('yweather:units') 56 | xml_astron = dom.getElementsByTagName('yweather:astronomy') 57 | #Get today Tag 58 | current = xml_current[0] 59 | today = xml_temperatures[4] 60 | wind = xml_wind[0] 61 | location = xml_location[0] 62 | atmos = xml_atmos[0] 63 | units = xml_units[0] 64 | astron = xml_astron[0] 65 | #Get info 66 | status = current.getAttribute('text') 67 | image = current.getAttribute('code') 68 | date = current.getAttribute('date') 69 | concisedates = date.split() 70 | concisedate = ' '.join([concisedates[2],concisedates[1].lstrip("0")]) 71 | concisetime = ' '.join([concisedates[4],concisedates[5]]) 72 | 73 | temp = current.getAttribute('temp') 74 | low = today.getAttribute('low') 75 | high = today.getAttribute('high') 76 | #chill = wind.getAttribute('chill') 77 | direction = wind.getAttribute('direction') 78 | speed = wind.getAttribute('speed') 79 | humidity = atmos.getAttribute('humidity') 80 | pressure = atmos.getAttribute('pressure') 81 | pressureunit = units.getAttribute('pressure') 82 | city = location.getAttribute('city') 83 | sunset = astron.getAttribute('sunset') 84 | sunrise = astron.getAttribute('sunrise') 85 | image_url = 'assets/' + image + '.png' 86 | 87 | # Open SVG to process 88 | output = codecs.open('template.svg', 'r', encoding='utf-8').read() 89 | 90 | 91 | # Insert icons and temperatures 92 | output = output.replace('TODAY',concisedate) 93 | output = output.replace('TIME',concisetime) 94 | output = output.replace('CITY',city) 95 | output = output.replace('HUMID',humidity) 96 | output = output.replace('ICON_ONE',image_url) 97 | output = output.replace('HIGH_ONE',temp) 98 | 99 | output = output.replace('LOW_ONE',chill) 100 | output = output.replace('SUNSET',sunset.rstrip(' pm')) 101 | output = output.replace('SUNRISE',sunrise.rstrip(' am')) 102 | 103 | output = output.replace('STATUS',status) 104 | if chill>=temp: 105 | output = output.replace('black','white') 106 | output = output.replace('TEMPYCOORD','310') 107 | else: 108 | output = output.replace('TEMPYCOORD','270') 109 | 110 | 111 | output = output.replace('SPEED',str(int(round(float(speed))))) 112 | output = output.replace('NESW',getCardinal(float(direction))) 113 | if METRIC: 114 | output = output.replace('UNIT','km/h') 115 | else: 116 | output = output.replace('UNIT','mph') 117 | # Write output 118 | codecs.open('weather-processed.svg', 'w', encoding='utf-8').write(output) 119 | --------------------------------------------------------------------------------