Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor")
- local tzDif = -7
- local date = "????-??-??"
- local time = "??:?? ??"
- local slowWaitTime = 10
- local fastWaitTime = 3
- local cHour = 0
- local cMin = 0
- local hrsUntil = 0
- local DAY = 0
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextScale(4)
- os.loadAPI("json")
- local json = _G.json
- _G.json = nil
- local function redraw()
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write(date)
- mon.setCursorPos(1,2)
- mon.write(time)
- mon.setCursorPos(1,5)
- mon.write(tostring(hrsUntil) .. " hrs adv")
- end
- local function updateDate(yr,mn,d)
- --"????-??-??"
- -- 1234567890
- if type(yr) == "string" then
- date = yr .. date:sub(5)
- end
- if type(mn) == "string" then
- date = date:sub(1,5) .. mn .. date:sub(8)
- end
- if type(d) == "string" then
- if d:len() < 2 then
- d = "0" .. d
- end
- date = date:sub(1,8) .. d
- end
- end
- local function updateTime(hr,mn)
- --"??:?? ??"
- -- 12345678
- if type(hr) == "string" then
- local ampm = "??"
- local n = tonumber(hr) + tzDif
- if n < 0 then
- n = 24 + n
- updateDate(nil,nil,tostring(DAY-1))
- end
- hrsUntil = 22 - n
- if hrsUntil < 0 then hrsUntil = 24 + hrsUntil end
- if n > 12 then
- ampm = "PM"
- n = n - 12
- elseif n == 12 then
- ampm = "PM"
- elseif n < 12 then
- ampm = "AM"
- if n == 0 then
- n = 12
- end
- end
- n = tostring(n)
- if n:len() < 2 then
- n = "0" .. n
- end
- time = n .. time:sub(3,6) .. ampm
- end
- if type(mn) == "string" then
- time = time:sub(1,3) .. mn .. time:sub(6)
- end
- end
- redraw()
- local function timeWatch()
- while true do
- if cHour == 22 and cMin == 0 then
- mon.clear()
- mon.setCursorPos(1,1)
- mon.setTextScale(1)
- shell.run("monitor right shell")
- mon.setTextScale(4)
- end
- if cHour == 21 then
- if cMin > 55 then
- print()
- mon.setCursorPos(1,3)
- mon.write("ADVENT")
- mon.setCursorPos(1,4)
- mon.write("SOON")
- os.sleep(fastWaitTime)
- else
- os.sleep(slowWaitTime)
- end
- else
- os.sleep(slowWaitTime)
- end
- local h = {http.get("http://worldclockapi.com/api/json/utc/now")}
- if h[1] then
- local data = json.decode(h[1].readAll())
- h[1].close()
- --Date / Time Format:
- --[[
- 2018-12-02T06:13:Z
- ]]
- if type(data) == "table" then
- if data["currentDateTime"] then
- local year, month, day, hour, minute = string.match(data["currentDateTime"],"(%d+)-(%d+)-(%d+)T(%d+):(%d+)Z")
- updateDate(year,month,day)
- DAY = tonumber(day)
- updateTime(hour,minute)
- cHour = tonumber(hour)
- cMin = tonumber(minute)
- else
- date = "????-??-?1"
- time = "??:?? ??"
- end
- else
- date = "????-??-?2"
- time = "??:?? ??"
- end
- else
- date = "????-??-?3"
- time = "??:?? ??"
- end
- redraw()
- end
- end
- timeWatch()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement