Last active
November 20, 2017 20:29
-
-
Save dvcrn/047e9bf5402e608453281ba6753d9a25 to your computer and use it in GitHub Desktop.
Fetch crypto price in applescript
This file contains 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
# example to fetch the current MONA price in JPY | |
# needs http://www.mousedown.net/mouseware/JSONHelper.html | |
# replace 'neo' with any other ID supported by coinmarketcap | |
# using coinmarketcaps convert API to add `price_jpy` to the result | |
set json_data to (do shell script "curl https://api.coinmarketcap.com/v1/ticker/monacoin/?convert=JPY") | |
tell application "JSON Helper" | |
set json_data to read JSON from json_data | |
end tell | |
set first_result to beginning of json_data | |
set price to price_jpy of first_result as number | |
# round result to 2 decimal places | |
set rounded_price to (round (price * 100)) / 100 | |
set result_string to "" & rounded_price & "円" | |
# (...) | |
# do what you want with result_string |
This file contains 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
# example to fetch the current NEO price | |
# needs http://www.mousedown.net/mouseware/JSONHelper.html | |
# replace 'neo' with any other ID supported by coinmarketcap | |
set json_data to (do shell script "curl https://api.coinmarketcap.com/v1/ticker/neo/") | |
tell application "JSON Helper" | |
set json_data to read JSON from json_data | |
end tell | |
set first_result to beginning of json_data | |
set price to price_usd of first_result as number | |
set result_string to "$" & price | |
# (...) | |
# do what you want with result_string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment