Skip to content

Instantly share code, notes, and snippets.

@windoze95
Created June 24, 2017 22:12
Show Gist options
  • Save windoze95/f68549307e5fcb5cbce61907cae1dc32 to your computer and use it in GitHub Desktop.
Save windoze95/f68549307e5fcb5cbce61907cae1dc32 to your computer and use it in GitHub Desktop.
Lua script to call coinmarketcap.com api for cryptocurrency info/ticker
local json = require("json")
function command(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
local res = command("curl -s 'https://api.coinmarketcap.com/v1/ticker/?limit=2'")
local o = json.decode(res)
local eth = o[2]
print(eth["name"], eth["price_usd"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment