Remove ccurrency and adapt own crypto script

This commit is contained in:
flyingscorpio@arch-desktop 2020-05-06 11:05:07 +02:00
parent 0c59a3a3ec
commit 172920b594
2 changed files with 37 additions and 10 deletions

View file

@ -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

View file

@ -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()))