16.01.2019, 05:35
Hi
I'd like to pull weather data from the Australian BOM XML data feed however need some assistance in processing their (complex) XML.
The data for the Melbourne forecast can easily be downloading via the following script and I've identified the info I need (commented out in the code below). however need some help to traverse the XML using the tools available in lua.
Any help would be greatly appreciated
Kind Regards
James
I'd like to pull weather data from the Australian BOM XML data feed however need some assistance in processing their (complex) XML.
The data for the Melbourne forecast can easily be downloading via the following script and I've identified the info I need (commented out in the code below). however need some help to traverse the XML using the tools available in lua.
Any help would be greatly appreciated
Kind Regards
James
Code:
require('socket.ftp')
data = socket.ftp.get('ftp://ftp.bom.gov.au/anon/gen/fwo/IDV10450.xml')
if data then
require('lxp')
-- retrieve data from XML node
-- Weather_Temp_Max = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='1']/element[@type='air_temperature_maximum']/text()")[0]
-- Weather_Temp_Min = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='1']/element[@type='air_temperature_minimum']/text()")[0]
-- Weather_Rain = tree.xpath("//forecast/area[@aac='VIC_PT042']/forecast-period[@index='1']/text[@type='probability_of_precipitation']/text()")[0]
grp.write('1/1/100',Weather_Temp_Max)
grp.write('1/1/101',Weather_Temp_Min)
grp.write('1/1/102',Weather_Rain)
else
log('Fetch failed to retrieve weather data')
end