Crypto design fix #9
3 changed files with 15 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue