Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Sending an HTTP request...")
- local getres = http.get("http://www.worldtimeserver.com/current_time_in_DE.aspx?city=Berlin")
- local readRes = getres.readAll()
- local unfilteredTime = string.sub(readRes,string.find(readRes, "(%d+:%d+) %aM")) --find time with AP/PM
- local s, e = string.find(readRes, "<strong>%s+%u(.+)%d?</strong>")
- s, e = s + 49, e - 9
- local worldDate = string.sub( readRes, s, e)
- --print( unfilteredTime )
- local unfHour = string.sub(string.sub(unfilteredTime, string.find( unfilteredTime, "%d+:" ) ), 1, -2)
- local unfMinute = string.sub(string.sub(unfilteredTime, string.find( unfilteredTime, ":%d+" ) ), 2, 4)
- --print("Its "..unfHour..":"..unfMinute)
- local apm = string.lower(string.sub(unfilteredTime, -2)) --find out PM or AM
- --print(apm)
- if apm == "pm" then
- hour = unfHour + 12
- elseif apm == "am" then
- if unfHour < 10 then
- hour = "0"..unfHour
- end
- else
- errorCode = "Couldn't get AM/PM!"
- end
- -- <strong>
- -- Thursday, April 04, 2013</strong>
- local worldTime = hour..":"..unfMinute
- print("Current time: "..worldTime.." on "..worldDate)
- function writeToFile(fileName)
- local absPath = shell.resolve( fileName )
- local file
- if not fs.exists( absPath ) then
- print("Creating a new time log file with name \""..fileName.."\"!")
- file = fs.open( absPath, "w" )
- else
- file = fs.open( absPath, "a" ) -- w+ aka writeUpdate mode
- end
- file.write("Current time: "..worldTime.." on "..worldDate.."\n")
- file.close()
- end
- writeToFile("time.log")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement