Haha. Ya, well that is good to know. I was really trying to get the weather script working for my netbook which has CrunchBang installed on it. Currently I have a text based weather system that is stealing xmms from the NOAA website. Here my choppy python script if anyone else wants to use/refine it.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################
# RETRIEVES NATIONAL WEATHER SERVICE XMMS FEEDS (USA ) #
###############################################################################
# CREATE A FILE CWI.cfg WITH THE CALL SIGNS OF THE NEAREST
# AIRPORT CALL SIGN AND STATE ABBREVIATION EXAMPLE
#(EXTRA # INCLUDED FOR COMMENT):
###WEATHER (EL PASO, TX)
##CALLSIGN #STATE
#KELP TX
#THEN USE python CWI.py -l: CURRENT LOCATION
# OR USE python CWI.py -t: CURRENT WEATHER TYPE
# OR USE python CWI.py -T: CURRENT TEMPERATURE
# OR USE python CWI.py -P: CURRENT FORCAST PICTURE/SYMBOL
#FOR EXTENDED FORECASTS USE
# OR USE python CWI.py -et <ndays+>: WEATHER TYPE <ndays+> IN ADVANCE
# OR USE python CWI.py -eT <ndays+>: TEMPERATURE FORECAST <ndays+> IN ADVANCE
# OR USE python CWI.py -eP <ndays+>: PICTURE/SYMBOL <ndays+> IN ADVANCE
# OR USE python CWI.py -D <ndays+>: TO OUTPUT THE DATE OF <ndays+>
#NOTE: THERE MAY ONLY BE A 4 DAY OUTLOOK!
################################################################################
import sys
import os
import logging
import time
from datetime import datetime, timedelta
import urllib
global upath
upath = os.path.expanduser("~/")
#READ SAVED LOCATION DATA
def readSavedSettings():
settings = open(upath+"/CWI.cfg",'r')
linesread = 0
while True:
text = settings.readline()
#LOOK FOR EOF
if text == '':
#print "EOF"
break
if linesread == 1:
break
#OTHERWISE READ
elif text[0] == '#':
#print text
continue
elif linesread == 0:
call_sign, state = text.split()
linesread = linesread + 1
settings.close()
return (call_sign, state)
#REMOVE XML FORMATTING GARBAGE ----------------------------------------------------------------
def Remove_XML_Junk(string):
for i in range(0, 2):
openbracket = string.find("<")
closebracket = string.find(">")
removestr = string[openbracket:closebracket+1]
string = string.replace(removestr, '')
string = string.strip()
return(string)
#REMOVE LIST QUOTES ---------------------------------------------------------------------------
def Get_Quoted(string):
openquote = string.find('"')
closequote = string.rfind('"')
string = string[openquote+1:closequote]
return(string)
#GET CURRENT FORECAST INFO
def ParseCurrentNWSXML(CurCond, CurXMLfeed):
while True:
xmltext = CurXMLfeed.readline()
#print xmltext
CurCond.append(Remove_XML_Junk(xmltext))
if xmltext == '':
break
CurCond = CurCond[15:len(CurCond)-10]
#print CurCond
Location = CurCond[0]
curtemp_str = CurCond[7]
return CurCond
#GET 48 HOUR WEATHER RESULTS
def ParseNWSXML(TempMin, TempMax, PrecipC, WeathType, TextFcast, XMLfeed):
while True:
xmltext = XMLfeed.readline()
#print xmltext
minTemps = xmltext.find("Daily Minimum")
if minTemps != -1:
for i in range(0, 7):
TempMin.append(Remove_XML_Junk(XMLfeed.readline()))
maxTemps = xmltext.find("Daily Maximum")
if maxTemps != -1:
for i in range(0, 7):
TempMax.append(Remove_XML_Junk(XMLfeed.readline()))
precChance = xmltext.find("12 Hourly Probability of Precipitation")
if precChance != -1:
for i in range(0, 7):
PrecipC.append(Remove_XML_Junk(XMLfeed.readline()))
wX = xmltext.find("Weather Type, Coverage, Intensity")
if wX != -1:
for i in range(0, 7):
WeathType.append(Get_Quoted(XMLfeed.readline()))
wForecast = xmltext.find("Text Forecast")
if wForecast != -1:
for i in range(0, 14):
TextFcast.append(Remove_XML_Junk(XMLfeed.readline()))
if xmltext == '':
break
return[TempMin, TempMax, PrecipC, WeathType, TextFcast]
#GET DATA FROM NWS -------------------------------------------------------------------------------------------------------------
def getWeather(wtp, days_ahead=0):
global path
days_ahead = int(days_ahead)
#####################################################################
TempMin = ]
TempMax = ]
PrecipC = ]
WeathType = ]
TextFcast = ]
CurCond = ]
CallList = ]
call_sign, state = readSavedSettings()
date = datetime.today() + timedelta(days=days_ahead)
date = str(date).split(' ')
year, month, day = date[0].split('-')
CurXMLfeed = urllib.urlopen("http://www.weather.gov/xml/current_obs/"+call_sign+".xml")
CurCond = ParseCurrentNWSXML(CurCond, CurXMLfeed)
latitude = CurCond[2]
longitude = CurCond[3]
XMLfeed = urllib.urlopen("http://forecast.weather.gov/MapClick.php?lat="+latitude+"&lon="+longitude+"&FcstType=dwml")
TempMin, TempMax, PrecipC, WeathType, TextFcast = ParseNWSXML(TempMin, TempMax, PrecipC, WeathType, TextFcast, XMLfeed)
#print date
#print TempMin
#print TempMax
#print PrecipC
#print WeathType
#print TextFcast
#print CurCond
#return [TempMin, TempMax, PrecipC, WeathType, TextFcast, CurCond]
#FOR NOW THE CURRENT CONDITION IS A GOOD START, TRY AND FIX THE REST LATER
#FORMAT THIS FOR AN EAST CONKY PRINT???
ccond_type = CurCond[6]
ccond_temp = CurCond[7]
ccond_loca = CurCond[0]
if wtp == '-D':
print month+'-'+day
#PRINT THE WEATHER TYPE
if wtp == '-t':
print ccond_type
#PRINT THE EXTENDED FORECAST WEATHER TYPE X days_ahead OF CURRENT
if wtp == '-et':
if days_ahead -1 >= 0:
print WeathType[days_ahead-1]
#PRINT THE CURRENT TEMPERATURE
if wtp == '-T':
print ccond_temp
#PRINT THE EXTENDED FORECAST HIGH & LOW TEMPS
if wtp == '-eT':
if days_ahead -1 >= 0:
print TempMax[days_ahead-1]+'/'+TempMin[days_ahead-1]
#GIVE THE REPORTING LOCATION OF THE FORECASTS
if wtp == '-l':
print ccond_loca
#GET THE CURRENT WEATHER PICTURE TYPE
if wtp == '-P':
if (ccond_type.lower().find('cloudy') != -1 and ccond_type.lower().find('partly')) or (ccond_type.lower().find('overcast') != -1):
print 'C'
if (ccond_type.lower().find('rain') != -1):
print 'R'
if (ccond_type.lower().find('sunny') != -1) or (ccond_type.lower().find('clear') != -1) or (ccond_type.lower().find('fair') != -1):
print 'S'
if (ccond_type.lower().find('snow') != -1) or (ccond_type.lower().find('sleet') != -1):
print 'O'
if (ccond_type.lower().find('partly cloudy') != -1) or (ccond_type.lower().find('a few clouds')) != -1:
print 'P'
if (ccond_type.lower().find('thunder') != -1) or (ccond_type.lower().find('tstorm') != -1):
print 'T'
#if (ccond_type.lower().find('windy') != -1) or (ccond_type.lower().find('gusty') != -1):
print 'W'
return ()
if __name__ == "__main__":
if len(sys.argv) == 2:
getWeather(sys.argv[1])
else:
getWeather(sys.argv[1], sys.argv[2])