Crypto design fix
Added 24H change
This commit is contained in:
parent
ccf28e52b7
commit
b0ac5504b2
3 changed files with 15 additions and 9 deletions
|
@ -9,16 +9,19 @@ class CryptoListDesign (DesignEntity):
|
||||||
def __init__ (self, size, coin, text_size = defaultfontsize):
|
def __init__ (self, size, coin, text_size = defaultfontsize):
|
||||||
super(CryptoListDesign, self).__init__(size)
|
super(CryptoListDesign, self).__init__(size)
|
||||||
self.coin = coin
|
self.coin = coin
|
||||||
self.__post_matrix__ = [[]]
|
self.__post_matrix__ = []
|
||||||
self.text_size = text_size
|
self.text_size = text_size
|
||||||
|
|
||||||
def __finish_image__ (self):
|
def __finish_image__ (self):
|
||||||
self.__fill_post_matrix__()
|
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)
|
self.draw_design(table_design)
|
||||||
|
|
||||||
|
def format_price(self,prices,coins,daychange):
|
||||||
|
return [ '', coins,' | ','$',prices,' | %',daychange]
|
||||||
|
|
||||||
def __fill_post_matrix__ (self):
|
def __fill_post_matrix__ (self):
|
||||||
prices, coins = CryptoPrices.__get_prices__(self.coin)
|
prices, coins, daychanges = CryptoPrices.__get_prices__(self.coin)
|
||||||
for price, coin in zip(prices, coins):
|
for price, coin, daychange in zip(prices, coins, daychanges):
|
||||||
row = coin + ": $" + str(price)
|
row=self.format_price(str(price), coin, str(daychange))
|
||||||
self.__post_matrix__[0].append(row)
|
self.__post_matrix__.append(row)
|
||||||
|
|
|
@ -20,10 +20,13 @@ class CryptoPrices(CryptoInterface):
|
||||||
def __get_prices__(self):
|
def __get_prices__(self):
|
||||||
price=[]
|
price=[]
|
||||||
name=[]
|
name=[]
|
||||||
|
daychange=[]
|
||||||
for coin in self.coins:
|
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'))
|
dataJSON = json.loads(data.decode('utf-8'))
|
||||||
raw = dataJSON[coin]["usd"]
|
raw = dataJSON[coin]["usd"]
|
||||||
|
raw24h = dataJSON[coin]["usd_24h_change"]
|
||||||
price.append(math.ceil(raw*100)/100)
|
price.append(math.ceil(raw*100)/100)
|
||||||
|
daychange.append(math.ceil(raw24h*100)/100)
|
||||||
name.append(coin)
|
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#"
|
"http://feeds.bbci.co.uk/news/world/rss.xml#"
|
||||||
]
|
]
|
||||||
|
|
||||||
crypto_coins = [
|
crypto_coins = [ #limit 8 coins @ font_size =14
|
||||||
"bitcoin",
|
"bitcoin",
|
||||||
"litecoin",
|
"litecoin",
|
||||||
"ethereum",
|
"ethereum",
|
||||||
|
|
Loading…
Reference in a new issue