From ee6884addd0112936d65b9c636ea5cdd6807e543 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Wed, 29 Apr 2020 13:52:45 +0200 Subject: [PATCH] Add own crypto script --- dotfiles/i3/blocks | 16 ++++++++++++---- dotfiles/i3/scripts/crypto | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) create mode 100755 dotfiles/i3/scripts/crypto diff --git a/dotfiles/i3/blocks b/dotfiles/i3/blocks index e2bd9dd..d2efead 100644 --- a/dotfiles/i3/blocks +++ b/dotfiles/i3/blocks @@ -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 diff --git a/dotfiles/i3/scripts/crypto b/dotfiles/i3/scripts/crypto new file mode 100755 index 0000000..f4154a1 --- /dev/null +++ b/dotfiles/i3/scripts/crypto @@ -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)))