Created
April 26, 2024 13:39
-
-
Save ademcan/01a0d92b63eba91f094df97fce15ce4e to your computer and use it in GitHub Desktop.
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
function notifyOnLowMempoolFees() | |
local log = hs.logger.new("mempoolFeesTimer", 5) | |
log.i("Tick") | |
local url = "https://mempool.space/api/v1/fees/recommended" | |
hs.http.asyncGet(url, {}, function(status, body) | |
if status ~= 200 then | |
log.wf("Unexpected result from Mempool. Status code: %s", status) | |
return nil | |
end | |
local fees = hs.json.decode(body) | |
if fees == nil then | |
log.wf("Failed to decode Mempool payload. Body: %s", body) | |
return nil | |
end | |
log.f("Fastest fee currently %s sat/vbyte", fees.fastestFee) | |
if fees.hourFee < 3 then | |
notify(string.format("The hourFee mempool fee is currently %s sat/vbyte !!", fees.hourFee)) | |
end | |
end) | |
end | |
function notify(text) | |
hs.notify.new({title="Hammerspoon", informativeText=text}):send() | |
end | |
function notifyError(errorText) | |
hs.notify.new({title="Hammerspoon Error", informativeText=errorText}):send() | |
end | |
globalTimers = {} | |
table.insert(globalTimers, hs.timer.doEvery(360, notifyOnLowMempoolFees)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment