#!/usr/bin/env python # -*- coding: utf-8 -*- # WEATHER SCRIPT (via Yahoo API) by Stolid # License: CC-BY-SA https://creativecommons.org/licenses/by-sa/3.0/ import os, urllib from xml.dom import minidom location = '12789137' #WOEID url = 'http://weather.yahooapis.com/forecastrss?w='+location+'&u=f' xml = minidom.parse(urllib.urlopen(url)) #forecast = day : (dayname, high, low, description) current = {'temp':-999, 'desc':'Default description'} forecast = {} # day : (dayname, high, low, description) a = xml.getElementsByTagName('channel')[0] b = a.getElementsByTagName('item')[0] c = b.getElementsByTagName('yweather:condition')[0] current['desc'] = c.attributes['text'].value current['temp'] = c.attributes['temp'].value d = b.getElementsByTagName('yweather:forecast') forecast['today'] = d[0].attributes['day'].value, d[0].attributes['high'].value, d[0].attributes['low'].value, d[0].attributes['text'].value forecast['tomorrow'] = d[1].attributes['day'].value, d[1].attributes['high'].value, d[1].attributes['low'].value, d[1].attributes['text'].value #Conky formatting (format1 is in front of the line, format2 is after the colon) format1 = '${color 729FCF}${font Source Sans Pro Regular:bold:size=10}' format2 = '$font$color ${goto 55}' conky = '{0}Now:{1} {2}°, {3}\n'.format(format1, format2, current['temp'], current['desc']) conky += '{0}{1}:{2} {3}° Hi, {4}° Low, {5}\n'.format(format1,forecast['today'][0],format2, forecast['today'][1], forecast['today'][2], forecast['today'][3]) conky += '{0}{1}:{2} {3}° Hi, {4}° Low, {5}\n'.format(format1,forecast['tomorrow'][0],format2, forecast['tomorrow'][1], forecast['tomorrow'][2], forecast['tomorrow'][3]) print conky