2004-01-25, 02:55
thanks for the idea... i made a simple python script to download current weather conditions and display them on your screen. the ui isn't great, but it works.
Quote:#display weather forecast on your xbox
########enter your zip code###########
zipcode = '94025'
import sys, urllib, string, urlparse, re, xbmc, xbmcgui
#will parse out text between given tag
def parsexml( line, tag ):
result= re.search('<' + tag + '>.*' + tag + '>', line, re.dotall)
try:
if result.group(0):
mod = string.replace(result.group(0), '<' + tag + '>','')
mod = string.replace(mod, '</' + tag + '>', '')
mod = string.lstrip(mod)
return mod
except:
return
url = 'http://www.rssweather.com/rss.php?config=&forecast=zandh&zipcode=' + zipcode + '&alt=rss20a'
data = urllib.urlopen(url)
currentline= data.read()
itemdivide= string.split(currentline, '<item>')
place= parsexml(itemdivide[0], 'title')
i=1
items= len(itemdivide)
dayforecast=[]
forecast=[]
while i < items:
check=parsexml(itemdivide[i], 'category')
if check=="current conditions":
time=parsexml(itemdivide[i], 'pubdate')
ctemp=parsexml(itemdivide[i], 'description')
if check=="weather forecast":
forecast.append(parsexml(itemdivide[i],'description'))
dayforecast.append(parsexml(itemdivide[i], 'title'))
i=i+1
# now we have all the parts we need so display to the user
dialog= xbmcgui.dialog()
dayforecast.insert(0, 'exit')
dayforecast.insert(0, 'current temperature: ' + ctemp)
dayforecast.insert(0, 'information from: ' + time)
selected= dialog.select(place, dayforecast)
if selected < 3:
print 'quitting..'
else:
dialog.ok(dayforecast[selected],forecast[selected-3])