Processing Australian BOM Weather XML Data - Printable Version +- Logic Machine Forum (https://forum.logicmachine.net) +-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1) +--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8) +--- Thread: Processing Australian BOM Weather XML Data (/showthread.php?tid=1836) |
Processing Australian BOM Weather XML Data - jamesng - 16.01.2019 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 Code: require('socket.ftp') RE: Processing Australian BOM Weather XML Data - admin - 16.01.2019 Since Expat library is stream-oriented, xpath cannot be used. Here's an example that parses the XML and retrieves the required fields: Code: require('socket.ftp') RE: Processing Australian BOM Weather XML Data - jamesng - 16.01.2019 Thank you so much for the solution and for the quick reply. It's working perfectly! If you don't mind me also asking, how can I extract the start-time-local value from the same forecast-period at index 1 and convert it to a lua Date data type? Kind Regards James RE: Processing Australian BOM Weather XML Data - admin - 16.01.2019 You can get start/end time as Lua table like this. Then you can either convert it to timestamp via os.time() or use it as object value directly. Code: function parsedatetime(str) RE: Processing Australian BOM Weather XML Data - jamesng - 16.01.2019 Again manu thanks for the code - I've added it to our system. We're using this info combined with local sensors to automatically open exterior blinds to keep the property cool this summer. Kind Regards James RE: Processing Australian BOM Weather XML Data - sgraystar - 12.10.2023 Fantastic. I came searching for parsing xml thinking I would have to start from scratch but the job has already been done. Thanks!! For future users, some of the BoM files contain forecasts for multiple locations so you can generalise by changing the start of the function to search location instead of aac Code: -- Product ID from FTP Public Products and wanted location within the BoM file |