From b58357927f41dd9d6391a5cd6e9734db95a667ba Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 22:08:14 +0200 Subject: [PATCH] Improved naming --- Calendar/GeckoCrypto.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Calendar/GeckoCrypto.py b/Calendar/GeckoCrypto.py index 0a2eed9..3f19d17 100644 --- a/Calendar/GeckoCrypto.py +++ b/Calendar/GeckoCrypto.py @@ -14,7 +14,7 @@ price_currency_sign = "$" class GeckoCrypto(CryptoInterface): def __init__(self, coins): - self.coin_names = coins + self.coin_ids = coins self.metadata = None super(GeckoCrypto, self).__init__() @@ -28,30 +28,30 @@ class GeckoCrypto(CryptoInterface): def __get_coins__(self): self.__prepare_metadata__() coins = [] - for name in self.coin_names: + for id in self.coin_ids: try: - data = urlopen(api_price_url + "?include_24hr_change=true&ids=" + self.metadata[name]['id'] + "&vs_currencies=" + price_currency).read() + data = urlopen(api_price_url + "?include_24hr_change=true&ids=" + self.metadata[id]['id'] + "&vs_currencies=" + price_currency).read() dataJSON = json.loads(data.decode('utf-8')) - raw = dataJSON[name][price_currency] + raw = dataJSON[id][price_currency] price = math.ceil(raw*100) / 100 - change = dataJSON[name]['usd_24h_change'] + change = dataJSON[id]['usd_24h_change'] - coins.append(self.__build_coin__(name, price, change)) + coins.append(self.__build_coin__(id, price, change)) except: - print("Gecko-Error [" + name + "]") + print("Gecko-Error [" + id + "]") return coins - def __build_coin__(self, name, value, change): + def __build_coin__(self, id, value, change): coin = CryptoCoin() - coin.name = self.metadata[name]['name'] + coin.name = self.metadata[id]['name'] coin.day_change = round(change, 2) coin.price = value coin.datetime = datetime.now() coin.fetch_datetime = datetime.now() coin.currency = price_currency_sign - coin.symbol = self.metadata[name]['symbol'] + coin.symbol = self.metadata[id]['symbol'] return coin @@ -59,4 +59,4 @@ class GeckoCrypto(CryptoInterface): self.metadata = None data = urlopen(api_metadata_url).read() dataJSON = json.loads(data.decode('utf-8')) - self.metadata = { coin['id'].lower() : coin for coin in dataJSON if coin['id'].lower() in self.coin_names } + self.metadata = { coin['id'].lower() : coin for coin in dataJSON if coin['id'].lower() in self.coin_ids }