Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- get the web page with the correct time on it - change as appropriate
- local file = http.get("http://www.timeanddate.com/worldclock/uk/london")
- -- define patterns to locate date/time in web page
- local timematch = "<span id=ct class=h1>"
- local datematch = "<span id=ctdat>"
- local endmatch = "</span>"
- if file == nil then
- -- if web page cannot be opened, display error
- print("Can't open webpage.")
- else
- -- loop through each line of web page
- while true do
- -- read line
- local ver = file.readLine()
- -- if nil then at the end of the page, break out of loop
- if ver == nil then break end
- -- find the time pattern
- p = string.find(ver,timematch)
- -- if found,
- if p ~= nil then
- -- get the position of the end pattern
- q = string.find(ver,endmatch,p)
- -- get the string inbetween
- t = string.sub(ver,p+string.len(timematch),q-1)
- -- output time
- write("Time: ")
- print(t)
- end
- -- find the date pattern
- p = string.find(ver,datematch)
- -- if found,
- if p ~= nil then
- -- get the position of the end pattern
- q = string.find(ver,endmatch,p)
- -- get the string inbetween
- d = string.sub(ver,p+string.len(datematch),q-1)
- -- output date
- write("Date: ")
- print(d)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement