Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --requires packages
- -- lua-socket--
- -- loads the HTTP module and any libraries it requires
- local ftp = require("socket.ftp")
- local body, head = ftp.get("ftp://ftp2.bom.gov.au/anon/gen/fwo/IDA00003.dat")
- local format = ""
- --converts string to lines
- function magiclines(s)
- if s:sub(-1)~="\n" then s=s.."\n" end
- return s:gmatch("(.-)\n")
- end
- function createWeatherTable(s)
- local datatable = {}
- local keys = {}
- --generate temporary format table
- local i = 0
- for value in string.gmatch(format, '([^#]+)') do
- keys[i] = value
- i = i + 1
- end
- i = 0
- for value in string.gmatch(s, '([^#]+)') do
- if((string.match(keys[i], "max") or string.match(keys[i], "min")) and tonumber(value) == nil ) then
- datatable[keys[i]] = " "
- i = i + 1
- else
- --replace i with value from other table
- datatable[keys[i]] = value
- --basic output
- print(keys[i]..": "..datatable[keys[i]])
- i = i + 1
- end
- end
- end
- --main
- local i = true;
- for line in magiclines(body) do
- --grab the first line
- if(i) then
- i = false
- format = line
- end
- --print values
- if string.match(line, "Melbourne") then
- createWeatherTable(line)
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement