06-01-2014, 03:54 PM | #1 |
Junior Member
Posts: 9
Karma: 10
Join Date: May 2014
Device: Kindle Paperwhite 2nd Generation
|
Coding Errors
I put this code under feeds for calibre and I kept getting error messages
Here is the code: #!/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&l at=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) |
06-01-2014, 04:29 PM | #2 | |
Grand Sorcerer
Posts: 12,662
Karma: 74532212
Join Date: Nov 2007
Location: Toronto
Device: Libra H2O, Libra Colour
|
It's easier to see your code if you wrap it in a [ code ] section; that way the indentation is preserved.
Quote:
|
|
Advert | |
|
Tags |
coding, errors |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Flightcrew says Errors, but Sigil says no Errors… | Barcelona | Sigil | 4 | 02-09-2012 07:13 AM |
Kindle 8 coding | Jamestoo | Workshop | 2 | 01-14-2012 11:34 AM |
Coding headings in color | Alda | ePub | 11 | 01-27-2011 07:57 AM |
Seriously thoughtful Coding Help Requested | poohbear_nc | Lounge | 10 | 08-24-2010 10:42 AM |
python coding... | alexxxm | Sony Reader | 8 | 01-31-2008 12:25 PM |