docs: config docs

This commit is contained in:
AngeD 2023-07-14 17:37:12 +02:00
parent fdac273ed4
commit 2760df07bd
2 changed files with 8 additions and 11 deletions

View File

@ -1,13 +1,9 @@
# crypto # 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 ## How-To
Set your coins, your currency and the format you want the output in crypto Set the `COINS`, `CURRENCY` and `FORMAT` you want in `crypto`.
You can get a list of valid id with:
```console
$ curl https://api.coingecko.com/api/v3/coins/list
```
```console ```console
$ ./crypto $ ./crypto
``` ```

9
crypto
View File

@ -3,24 +3,25 @@
import json import json
import requests import requests
# curl https://api.coingecko.com/api/v3/coins/list
COINS = [ COINS = [
# [id, symbol] # [id, symbol]
["bitcoin", "BTC"], ["bitcoin", "BTC"],
] ]
CUR = "usd" CURRENCY = "usd"
FMT = "{coin}=${price:.0f}" FORMAT = "{coin}=${price:.0f}"
def main(): def main():
coin_ids = ",".join([coin for coin in list(zip(*COINS))[0]]) 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}} # {'bitcoin': {'usd': 69420}}
prices = json.loads(requests.get(url).text) prices = json.loads(requests.get(url).text)
print( 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 for coin in COINS
] ]
) )