diff --git a/dotfiles/i3/blocks b/dotfiles/i3/blocks index 56564b7..621a0c0 100644 --- a/dotfiles/i3/blocks +++ b/dotfiles/i3/blocks @@ -61,21 +61,17 @@ DISK=/run/media/flyingscorpio/Backup [corona] interval=5 -[ccurrency] -command=scripts/ccurrency -f USD -interval=1800 - [crypto] command=scripts/crypto BTC -interval=1800 +interval=900 [crypto] command=scripts/crypto UCA -b EUR -r 5 -interval=1800 +interval=900 [crypto] command=scripts/crypto BAT -r 5 -interval=1800 +interval=900 [protonvpn] interval=5 diff --git a/dotfiles/i3/scripts/crypto b/dotfiles/i3/scripts/crypto index 29f7671..81326a3 100755 --- a/dotfiles/i3/scripts/crypto +++ b/dotfiles/i3/scripts/crypto @@ -1,10 +1,21 @@ #!/usr/bin/env python3 +"""Simple script for i3blocks to fetch crypto values from coinranking API. + +Author: flyingscorpio +""" + import argparse import requests -def parse_arguments(): +def parse_arguments() -> argparse.Namespace: + """Arguments consist of: + * a coin to look up + * the currency to set the value on (defaults to USD) + * the number of decimals + """ + parser = argparse.ArgumentParser() parser.add_argument("coin") parser.add_argument("-b", "--base", default="USD") @@ -13,7 +24,19 @@ def parse_arguments(): return args -def compute(args): + +def compute(args: argparse.Namespace) -> str: + """h""" + + symbols = { + "GBP": "£", + "EUR": "€", + "USD": "$", + "BTC": "", + "LTC": "Ł", + "ETH": "Ξ", + } + coin = args.coin.upper() base = args.base.upper() round_nb = args.round @@ -23,13 +46,21 @@ def compute(args): base, coin ) ) + + try: + coin = symbols[coin] + except KeyError: + pass + req_j = req.json() data = req_j["data"] base_sign = data["base"]["sign"] coin_data = data["coins"][0] price = float(coin_data["price"]) - return "{} = {}{}".format(coin, base_sign, round(price, round_nb)) + output = "{} = {}{}".format(coin, base_sign, round(price, round_nb)) + + return output print(compute(parse_arguments()))