Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not fs.exists("json") then
- shell.run("pastebin get 4nRg9CHU json")
- end
- os.loadAPI("json")
- --- UTILS ----
- local function split(inputstr, sep)
- if sep == nil then sep = "%s" end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- local function writeCenter(str, width, y)
- local x = (width - string.len(str) + 1) / 2
- term.setCursorPos(x, y)
- term.write(str)
- end
- --- FUNCTIONS ---
- local function getDatetime()
- local request = http.get("http://worldtimeapi.org/api/timezone/Europe/Paris.json")
- if request == nil then
- print("Not able to get datetime on the API.")
- return nil
- end
- local text = request.readAll()
- local jsonDatetime = json.decode(text)
- local datetime = jsonDatetime.utc_datetime
- local offset = jsonDatetime.utc_offset
- local dayOfWeek = jsonDatetime.day_of_week
- local days = {
- [0] = "dimanche",
- [1] = "lundi",
- [2] = "mardi",
- [3] = "jeudi",
- [4] = "vendredi",
- [5] = "samedi",
- [6] = "dimanche"
- }
- local infos = {}
- infos["dayOfWeek"] = days[dayOfWeek]
- local date = split(split(datetime, "T")[1], "-")
- infos["year"] = date[1]
- infos["month"] = date[2]
- infos["day"] = date[3]
- local time = split(split(datetime, "T")[2], ":")
- local offset = split(split(offset, ":")[1], "+")[1]
- infos["hour"] = (tonumber(time[1]) + tonumber(offset)) % 24
- infos["min"] = time[2]
- infos["sec"] = split(time[3], ".")[1]
- return infos
- end
- local function main()
- local mon = peripheral.find("monitor")
- if mon then
- term.redirect(mon)
- mon.setTextScale(2)
- end
- local w,h = term.getSize()
- local infos
- while true do
- infos = getDatetime()
- if infos then
- term.clear()
- term.setTextColor(colors.blue)
- writeCenter(string.upper(infos["dayOfWeek"]), w, 1)
- writeCenter(infos["day"] .. "/" .. infos["month"] .. "/" .. infos["day"], w, 3)
- writeCenter(infos["hour"] .. ":" .. infos["min"] .. ":" .. infos["sec"], w, 5)
- if infos["dayOfWeek"] == "dimanche" and infos["hour"] == "23" then
- term.setTextColor(colors.red)
- writeCenter("RESET", w, 2)
- writeCenter("BIENTOT", w, 4)
- end
- end
- sleep(1)
- end
- end
- main()
Add Comment
Please, Sign In to add comment