1
0
Fork 0
forked from Simnation/Main
Main/resources/[Developer]/[Mark]/av_weather/server/editable/_api.lua
2025-06-07 08:51:21 +02:00

26 lines
No EOL
1.3 KiB
Lua

local api_key = ""
function getTimeFromCity(zone, cb)
if not api_key or string.len(api_key) < 5 then
print("^3[WARNING] Please add your API Key in server/editable/_api.lua, make sure to read the docs first.^7")
print("^3[WARNING] Please add your API Key in server/editable/_api.lua, make sure to read the docs first.^7")
print("^3[WARNING] Please add your API Key in server/editable/_api.lua, make sure to read the docs first.^7")
cb(nil,nil,nil)
end
local apiUrl = "https://api.ipgeolocation.io/timezone?apiKey="..api_key.."&tz=" .. zone
dbug("getTimeFromCity()...", zone)
PerformHttpRequest(apiUrl, function(statusCode, responseText, headers)
if statusCode == 200 then
local responseData = json.decode(responseText)
if responseData and responseData.time_24 then
local datetime = responseData.time_24
local hour, minutes, seconds = string.match(datetime, "(%d%d):(%d%d):(%d%d)")
cb(hour, minutes, seconds)
else
cb(nil, nil, nil, "Error: No date/time info received")
end
else
cb(nil, nil, nil, "Error: Request Error Code: " .. statusCode)
end
end, "GET", "", {})
end