Created
April 9, 2019 07:27
-
-
Save blacklee/7425b1f7b3e16acbfa9d1bbf04bdea28 to your computer and use it in GitHub Desktop.
Hammerspoon-AQI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local url = "https://api.waqi.info/feed/@UID/?token=Demo-Token" | |
-- fill your UID and token | |
local menubar = hs.menubar.new() | |
function getColor(aqi) | |
if aqi <= 50 then | |
return {red = 0, blue = 0, green = 1} | |
end | |
if aqi <= 100 then | |
return {red = 1, blue = 0.2, green = 0.7} | |
end | |
if aqi <= 150 then | |
return {red = 1, blue = 0, green = 0} | |
end | |
return {red = 0.27, blue = 0.6, green = 0.2} | |
end | |
function getAQI() | |
code, body, htable = hs.http.get(url, nil) | |
if code ~= 200 then | |
print("get AQI error:"..code) | |
return | |
end | |
json = hs.json.decode(body) | |
aqi = json.data.aqi | |
textColor = getColor(aqi) | |
menubar:setTitle(hs.styledtext.new(aqi, { color = textColor})) | |
end | |
menubar:setTitle("AQI..") | |
getAQI() | |
timer = hs.timer.new(900, getAQI) | |
timer:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment