Graph workds but indexes aren't clear
This commit is contained in:
parent
c0a59e4c69
commit
89b1bd4299
1 changed files with 18 additions and 4 deletions
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue