From 89b1bd429910f2c56f59c7edc0ac1d65eb059b98 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Sat, 16 May 2020 21:36:50 +0200 Subject: [PATCH] Graph workds but indexes aren't clear --- dotfiles/i3/scripts/crypto | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/dotfiles/i3/scripts/crypto b/dotfiles/i3/scripts/crypto index 176615f..1180175 100755 --- a/dotfiles/i3/scripts/crypto +++ b/dotfiles/i3/scripts/crypto @@ -6,7 +6,11 @@ Author: flyingscorpio """ import argparse +import os import requests +from typing import List + +import matplotlib.pyplot as plt # type: ignore def parse_arguments() -> argparse.Namespace: @@ -25,6 +29,13 @@ def parse_arguments() -> argparse.Namespace: return args +def generate_graph(data: List[float]) -> None: + """Generate a graph based on the numbers in data.""" + + plt.plot(data) + plt.show() + + def compute(args: argparse.Namespace) -> str: """Send a request to the API with the given arguments.""" @@ -42,8 +53,9 @@ def compute(args: argparse.Namespace) -> str: round_nb = args.round req = requests.get( - "https://api.coinranking.com/v1/public/coins" - "?base={}&symbols={}&timePeriod=30d".format(base, coin) + "https://api.coinranking.com/v1/public/coins?base={}&symbols={}&timePeriod=30d".format( + base, coin + ) ) try: @@ -56,8 +68,10 @@ def compute(args: argparse.Namespace) -> str: base_sign = data["base"]["sign"] coin_data = data["coins"][0] price = float(coin_data["price"]) - history = coin_data["history"] - print(history) + history = [float(value) for value in coin_data["history"]] + clicked = os.environ.get("BLOCK_BUTTON", "") + if clicked: + generate_graph(history) output = "{} = {}{}".format(coin, base_sign, round(price, round_nb))