Skip to content

Instantly share code, notes, and snippets.

@diix
Last active December 15, 2017 01:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diix/b56ae78372e335e458f7394f0e3c7dbd to your computer and use it in GitHub Desktop.
Save diix/b56ae78372e335e458f7394f0e3c7dbd to your computer and use it in GitHub Desktop.
touchbar
on replace_chars(this_text, search_string, replacement_string)
if this_text contains the search_string then
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
end if
return this_text
end replace_chars
set stockValue to do shell script "curl -s 'https://api.coinmarketcap.com/v1/ticker/bitcoin/' | grep 'price_usd'"
set stockValue to replace_chars(stockValue, " \"price_usd\": \"", "")
set stockValue to replace_chars(stockValue, "\",", "")
return "" & "$" & stockValue
on floor(x)
local x
try
return round (x) rounding down
on error eMsg number eNum
error "Can't floor(x): " & eMsg number eNum
end try
end floor
tell application "JSON Helper"
set fetch_api to fetch JSON from "https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR" with cleaning feed
end tell
set usd_price to price_eur of first item of fetch_api
set eur_price to price_usd of first item of fetch_api
set change to percent_change_24h of first item of fetch_api
return ("€" & floor(usd_price) & " [" & change & "%]")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment