diff --git a/README.md b/README.md index 7e99e3b..4b30794 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,9 @@ # crypto -Get your current holding in crypto from CoinGecko in your own currency. +Get the `value` of one+ `coin` from CoinGecko in the `currency` of your +`choice`. ## How-To -Set your coins, your currency and the format you want the output in crypto -You can get a list of valid id with: -```console -$ curl https://api.coingecko.com/api/v3/coins/list -``` - +Set the `COINS`, `CURRENCY` and `FORMAT` you want in `crypto`. ```console $ ./crypto ``` diff --git a/crypto b/crypto index 8953526..8c36647 100755 --- a/crypto +++ b/crypto @@ -3,24 +3,25 @@ import json import requests +# curl https://api.coingecko.com/api/v3/coins/list COINS = [ # [id, symbol] ["bitcoin", "BTC"], ] -CUR = "usd" -FMT = "{coin}=${price:.0f}" +CURRENCY = "usd" +FORMAT = "{coin}=${price:.0f}" def main(): coin_ids = ",".join([coin for coin in list(zip(*COINS))[0]]) - url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_ids}&vs_currencies={CUR}" + url = f"https://api.coingecko.com/api/v3/simple/price?ids={coin_ids}&vs_currencies={CURRENCY}" # {'bitcoin': {'usd': 69420}} prices = json.loads(requests.get(url).text) print( *[ - FMT.format(coin=coin[1], price=prices[coin[0]][CUR]) + FORMAT.format(coin=coin[1], price=prices[coin[0]][CURRENCY]) for coin in COINS ] )