Add own crypto script

This commit is contained in:
flyingscorpio@arch-desktop 2020-04-29 13:52:45 +02:00
parent 3c24346317
commit ee6884addd
2 changed files with 37 additions and 4 deletions

View file

@ -60,11 +60,19 @@ DISK=/run/media/flyingscorpio/Backup
[ccurrency]
command=scripts/ccurrency -f USD
interval=1800
interval=900
[ccurrency]
command=scripts/ccurrency -c ETH -f USD
interval=1800
[crypto]
command=scripts/crypto BTC
interval=10
[crypto]
command=scripts/crypto UCA -b EUR -r 5
interval=10
[crypto]
command=scripts/crypto BAT -r 5
interval=10
[protonvpn]
interval=5

25
dotfiles/i3/scripts/crypto Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import argparse
import requests
parser = argparse.ArgumentParser()
parser.add_argument("coin")
parser.add_argument("-b", "--base", default="USD")
parser.add_argument("-r", "--round", type=int, default=2)
args = parser.parse_args()
coin = args.coin.upper()
base = args.base.upper()
round_nb = args.round
req = requests.get(
"https://api.coinranking.com/v1/public/coins?base={}&symbols={}".format(base, coin)
)
req_j = req.json()
data = req_j["data"]
base_sign = data["base"]["sign"]
coin_data = data["coins"][0]
price = float(coin_data["price"])
print("{} = {}{}".format(coin, base_sign, round(price, round_nb)))