OK, i modified it to include this:
#!/usr/bin/python
import urllib2
from lxml import etree
It works now but I get these errors, any thoughts?
Requesting file...
File received...
Updating OpenHAB...
BOM_Temp_Max_0=24
Error with air_temperature_maximum::element::0
BOM_Precipitation_Range_0=2 to 10 mm
Error with precipitation_range::element::0
BOM_Forecast_Icon_Code_0=16
Error with forecast_icon_code::element::0
BOM_Precis_0=Showers increasing. Possible afternoon storm.
Error with precis::text::0
BOM_Precipitation_0=80%
Error with probability_of_precipitation::text::0
BOM_Temp_Max_1=26
Error with air_temperature_maximum::element::1
BOM_Temp_Min_1=17
Error with air_temperature_minimum::element::1
Error with precipitation_range::element::1
BOM_Forecast_Icon_Code_1=3
Error with forecast_icon_code::element::1
BOM_Precis_1=Partly cloudy.
Error with precis::text::1
BOM_Precipitation_1=5%
Error with probability_of_precipitation::text::1
End
Script:
#!/usr/bin/python
import urllib2
from lxml import etree
urlBase = 'http://192.168.0.3:8080/classicui/CMD?'
url = 'ftp://ftp.bom.gov.au/anon/gen/fwo/IDN10064.xml'
def setFWOItem(BOMName,OpenHABName,day,nodeType):
try:
value = tree.xpath("//forecast/area[@aac='NSW_PT131']/forecast-period[@index='" + day + "']/" + nodeType + "[@type='" + BOMName + "']/text()")[0]
OpenHABName = OpenHABName + "_" + day
print(" " + OpenHABName + "=" + value)
value = urllib2.parse.quote_plus(value, safe='', encoding=None, errors=None)
rawPage = urllib2.urlopen(urlBase + OpenHABName + '=' + value)
except:
print(" Error with " + BOMName + "::" + nodeType + "::" + day)
print('Requesting file...')
rawPage = urllib2.urlopen(url)
print('File received...')
read = rawPage.read()
tree = etree.XML(read)
print('Updating OpenHAB...')
rawPage = urllib2.urlopen(urlBase + 'BOMUpdating=ON')
setFWOItem("air_temperature_maximum","BOM_Temp_Max","0","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","0","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","0","element")
setFWOItem("precis","BOM_Precis","0","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","0","text")
setFWOItem("air_temperature_maximum","BOM_Temp_Max","1","element")
setFWOItem("air_temperature_minimum","BOM_Temp_Min","1","element")
setFWOItem("precipitation_range","BOM_Precipitation_Range","1","element")
setFWOItem("forecast_icon_code","BOM_Forecast_Icon_Code","1","element")
setFWOItem("precis","BOM_Precis","1","text")
setFWOItem("probability_of_precipitation","BOM_Precipitation","1","text")
rawPage = urllib2.urlopen(urlBase + 'BOMUpdating=OFF')
print('End')