diff --git a/Calendar/CryptoListDesign.py b/Calendar/CryptoListDesign.py index dbce17a..cb1ae0a 100644 --- a/Calendar/CryptoListDesign.py +++ b/Calendar/CryptoListDesign.py @@ -9,16 +9,19 @@ class CryptoListDesign (DesignEntity): def __init__ (self, size, coin, text_size = defaultfontsize): super(CryptoListDesign, self).__init__(size) self.coin = coin - self.__post_matrix__ = [[]] + self.__post_matrix__ = [] self.text_size = text_size def __finish_image__ (self): self.__fill_post_matrix__() - table_design = TableDesign(self.size, line_spacing=2, col_spacing=3, matrix=self.__post_matrix__, fontsize = self.text_size, mask=False, wrap=True, truncate_rows=True) + table_design = TableDesign(self.size, column_horizontal_alignments = ["Right"], line_spacing=2, col_spacing=3, matrix=self.__post_matrix__, fontsize = self.text_size, mask=False, wrap=True, truncate_rows=True) self.draw_design(table_design) + def format_price(self,prices,coins,daychange): + return [ '', coins,' | ','$',prices,' | %',daychange] + def __fill_post_matrix__ (self): - prices, coins = CryptoPrices.__get_prices__(self.coin) - for price, coin in zip(prices, coins): - row = coin + ": $" + str(price) - self.__post_matrix__[0].append(row) + prices, coins, daychanges = CryptoPrices.__get_prices__(self.coin) + for price, coin, daychange in zip(prices, coins, daychanges): + row=self.format_price(str(price), coin, str(daychange)) + self.__post_matrix__.append(row) diff --git a/Calendar/CryptoPrices.py b/Calendar/CryptoPrices.py index a31d950..7c4256c 100644 --- a/Calendar/CryptoPrices.py +++ b/Calendar/CryptoPrices.py @@ -20,10 +20,13 @@ class CryptoPrices(CryptoInterface): def __get_prices__(self): price=[] name=[] + daychange=[] for coin in self.coins: - data = urllib.request.urlopen("https://api.coingecko.com/api/v3/simple/price?ids="+coin+"&vs_currencies=USD").read() + data = urllib.request.urlopen("https://api.coingecko.com/api/v3/simple/price?ids="+coin+"&vs_currencies=USD&include_market_cap=false&include_24hr_vol=false&include_24hr_change=true&include_last_updated_at=false").read() dataJSON = json.loads(data.decode('utf-8')) raw = dataJSON[coin]["usd"] + raw24h = dataJSON[coin]["usd_24h_change"] price.append(math.ceil(raw*100)/100) + daychange.append(math.ceil(raw24h*100)/100) name.append(coin) - return price,name + return price,name,daychange diff --git a/Calendar/settings.py.sample b/Calendar/settings.py.sample index 46e0db6..e77bed7 100644 --- a/Calendar/settings.py.sample +++ b/Calendar/settings.py.sample @@ -11,7 +11,7 @@ rss_feeds = [ "http://feeds.bbci.co.uk/news/world/rss.xml#" ] -crypto_coins = [ +crypto_coins = [ #limit 8 coins @ font_size =14 "bitcoin", "litecoin", "ethereum",