LuaScripts/getTime.lua

23 lines
558 B
Lua
Raw Normal View History

2021-01-08 13:32:55 +00:00
local internet = require("internet")
2021-01-08 14:06:36 +00:00
local component = require("component")
local modem = component.modem
modem.open(69)
2021-01-08 13:32:55 +00:00
while true do
2021-01-08 14:38:47 +00:00
local handle = internet.request("http://api.timezonedb.com/v2.1/get-time-zone?key=INWE0H77BDN6&by=zone&zone=Europe/Moscow&format=json")
2021-01-08 13:32:55 +00:00
local result = ""
for chunk in handle do
result = result..chunk
end
local f = io.open("time.txt", "w")
2021-01-08 13:33:43 +00:00
f:write(result)
2021-01-08 13:50:10 +00:00
f:close()
2021-01-08 13:50:34 +00:00
f = io.open("time.txt", "r")
2021-01-08 14:38:47 +00:00
f:seek("set", 245)
local time = f:read(19)
2021-01-08 13:32:55 +00:00
f:close()
2021-01-08 14:38:47 +00:00
print(time)
--modem.broadcast(69, time)
2021-01-08 13:32:55 +00:00
end