Improved naming

This commit is contained in:
Maximilian Giller 2019-05-19 22:08:14 +02:00
parent b74def5bbf
commit b58357927f

View file

@ -14,7 +14,7 @@ price_currency_sign = "$"
class GeckoCrypto(CryptoInterface): class GeckoCrypto(CryptoInterface):
def __init__(self, coins): def __init__(self, coins):
self.coin_names = coins self.coin_ids = coins
self.metadata = None self.metadata = None
super(GeckoCrypto, self).__init__() super(GeckoCrypto, self).__init__()
@ -28,30 +28,30 @@ class GeckoCrypto(CryptoInterface):
def __get_coins__(self): def __get_coins__(self):
self.__prepare_metadata__() self.__prepare_metadata__()
coins = [] coins = []
for name in self.coin_names: for id in self.coin_ids:
try: 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')) dataJSON = json.loads(data.decode('utf-8'))
raw = dataJSON[name][price_currency] raw = dataJSON[id][price_currency]
price = math.ceil(raw*100) / 100 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: except:
print("Gecko-Error [" + name + "]") print("Gecko-Error [" + id + "]")
return coins return coins
def __build_coin__(self, name, value, change): def __build_coin__(self, id, value, change):
coin = CryptoCoin() coin = CryptoCoin()
coin.name = self.metadata[name]['name'] coin.name = self.metadata[id]['name']
coin.day_change = round(change, 2) coin.day_change = round(change, 2)
coin.price = value coin.price = value
coin.datetime = datetime.now() coin.datetime = datetime.now()
coin.fetch_datetime = datetime.now() coin.fetch_datetime = datetime.now()
coin.currency = price_currency_sign coin.currency = price_currency_sign
coin.symbol = self.metadata[name]['symbol'] coin.symbol = self.metadata[id]['symbol']
return coin return coin
@ -59,4 +59,4 @@ class GeckoCrypto(CryptoInterface):
self.metadata = None self.metadata = None
data = urlopen(api_metadata_url).read() data = urlopen(api_metadata_url).read()
dataJSON = json.loads(data.decode('utf-8')) 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 }