From ba8c95ff673b21155696f93c26dcb1b835f65729 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 00:22:24 +0200 Subject: [PATCH 1/8] Simple --- Calendar/CryptoCoin.py | 10 ++++++ Calendar/CryptoInterface.py | 18 ++++------- Calendar/CryptoItem.py | 4 --- Calendar/CryptoListDesign.py | 25 +++++++------- Calendar/CryptoPrices.py | 29 ----------------- Calendar/E-Paper.py | 10 +++--- Calendar/GeckoCrypto.py | 63 ++++++++++++++++++++++++++++++++++++ Installer-with-debug.sh | 4 ++- 8 files changed, 100 insertions(+), 63 deletions(-) create mode 100644 Calendar/CryptoCoin.py delete mode 100644 Calendar/CryptoItem.py delete mode 100644 Calendar/CryptoPrices.py create mode 100644 Calendar/GeckoCrypto.py diff --git a/Calendar/CryptoCoin.py b/Calendar/CryptoCoin.py new file mode 100644 index 0000000..3ad4f29 --- /dev/null +++ b/Calendar/CryptoCoin.py @@ -0,0 +1,10 @@ +class CryptoCoin(object): + def __init__ (self): + self.name = None + self.symbol = None + self.price = None + self.day_change = None + self.currency = None + self.datetime = None + + self.fetch_datetime = None \ No newline at end of file diff --git a/Calendar/CryptoInterface.py b/Calendar/CryptoInterface.py index fa3b7e5..5cceb75 100644 --- a/Calendar/CryptoInterface.py +++ b/Calendar/CryptoInterface.py @@ -1,22 +1,16 @@ from DataSourceInterface import DataSourceInterface -from datetime import datetime, timezone, timedelta class CryptoInterface(DataSourceInterface): def __init__(self): - self.crypto_prices = [] + self.crypto_coins = [] def reload(self): if self.is_available() == False: return - self.crypto_prices= self.__get_prices__() - self.sort_prices() + self.crypto_coins = self.__get_coins__() - def __get_prices__(self): - raise NotImplementedError("Functions needs to be implemented") + def __get_coins__(self): + raise NotImplementedError("Function needs to be implemented") - def get_latest_prices(self): - self.crypto_prices = self.crypto_prices - return self.crypto_prices - - def sort_prices(self): - self.crypto_prices =self.crypto_prices + def get_coins(self): + return self.crypto_coins diff --git a/Calendar/CryptoItem.py b/Calendar/CryptoItem.py deleted file mode 100644 index 83109fd..0000000 --- a/Calendar/CryptoItem.py +++ /dev/null @@ -1,4 +0,0 @@ -class CryptoItem(object): - def __init__ (self): - self.name = None - self.value = None diff --git a/Calendar/CryptoListDesign.py b/Calendar/CryptoListDesign.py index dbce17a..0efb5bf 100644 --- a/Calendar/CryptoListDesign.py +++ b/Calendar/CryptoListDesign.py @@ -1,24 +1,25 @@ from DesignEntity import DesignEntity from TableDesign import TableDesign from Assets import defaultfontsize -from CryptoPrices import CryptoPrices -from settings import crypto_coins as cryptos +from GeckoCrypto import GeckoCrypto +from settings import crypto_coins class CryptoListDesign (DesignEntity): - def __init__ (self, size, coin, text_size = defaultfontsize): + def __init__ (self, size, crypto, text_size = defaultfontsize): super(CryptoListDesign, self).__init__(size) - self.coin = coin - self.__post_matrix__ = [[]] + self.crypto = crypto 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) + matrix = self.__get_matrix__() + table_design = TableDesign(self.size, matrix=matrix, col_spacing=5, fontsize = self.text_size, mask=False, truncate_rows=True) self.draw_design(table_design) - 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) + def __get_matrix__ (self): + matrix = [] + coins = self.crypto.get_coins() + for coin in coins: + row = [ coin.symbol.upper(), coin.name, coin.currency + " " + str(coin.price), "% " + str(coin.day_change) ] + matrix.append(row) + return matrix diff --git a/Calendar/CryptoPrices.py b/Calendar/CryptoPrices.py deleted file mode 100644 index a31d950..0000000 --- a/Calendar/CryptoPrices.py +++ /dev/null @@ -1,29 +0,0 @@ -from CryptoInterface import CryptoInterface -from datetime import datetime, timedelta, date -import CryptoItem -import urllib.request -import json -import math - - -class CryptoPrices(CryptoInterface): - def __init__(self, coins): - self.coins = coins - super(CryptoPrices, self).__init__() - - def is_available(self): - if len(self.coins) > 0 and len(self.coins) < 8: - return True - else: - return False - - def __get_prices__(self): - price=[] - name=[] - for coin in self.coins: - data = urllib.request.urlopen("https://api.coingecko.com/api/v3/simple/price?ids="+coin+"&vs_currencies=USD").read() - dataJSON = json.loads(data.decode('utf-8')) - raw = dataJSON[coin]["usd"] - price.append(math.ceil(raw*100)/100) - name.append(coin) - return price,name diff --git a/Calendar/E-Paper.py b/Calendar/E-Paper.py index fef890a..0745d70 100644 --- a/Calendar/E-Paper.py +++ b/Calendar/E-Paper.py @@ -22,7 +22,7 @@ from AgendaListPanel import AgendaListPanel import OwmForecasts import IcalEvents import RssParserPosts -import CryptoPrices +from GeckoCrypto import GeckoCrypto all_locales = locale.locale_alias if language.lower() not in all_locales.keys(): @@ -62,7 +62,7 @@ def main(): owm = OwmForecasts.OwmForecasts(location, api_key, paid_api=owm_paid_subscription) events_cal = IcalEvents.IcalEvents(ical_urls, highlighted_ical_urls) rss = RssParserPosts.RssParserPosts(rss_feeds) - coin = CryptoPrices.CryptoPrices(crypto_coins) + crypto = GeckoCrypto(crypto_coins) while True: loop_timer.begin_loop() @@ -78,9 +78,9 @@ def main(): else: raise ImportError("choosen_design must be valid (" + choosen_design + ")") - debug.print_line('Getting crypto prices') - coin.reload() - design.add_crypto(coin) + debug.print_line('Fetching crypto prices from coin gecko') + crypto.reload() + design.add_crypto(crypto) debug.print_line("Fetching weather information from open weather map") owm.reload() diff --git a/Calendar/GeckoCrypto.py b/Calendar/GeckoCrypto.py new file mode 100644 index 0000000..051c5f7 --- /dev/null +++ b/Calendar/GeckoCrypto.py @@ -0,0 +1,63 @@ +from CryptoInterface import CryptoInterface +from datetime import datetime +from CryptoCoin import CryptoCoin +from urllib.request import urlopen +import json +import math + +api_test_url = "https://www.coingecko.com" +api_url = "https://api.coingecko.com/api/v3/" +api_metadata_url = api_url + "coins/list" +api_price_url = api_url + "simple/price" +price_currency = "usd" +price_currency_sign = "$" + +class GeckoCrypto(CryptoInterface): + def __init__(self, coins): + self.coin_names = coins + self.metadata = None + super(GeckoCrypto, self).__init__() + + def is_available(self): + return True + try: + urlopen(api_test_url) + return True + except: + return False + + def __get_coins__(self): + self.__prepare_metadata__() + coins = [] + for name in self.coin_names: + try: + data = urlopen(api_price_url + "?include_24hr_change=true&ids=" + self.metadata[name]['id'] + "&vs_currencies=" + price_currency).read() + dataJSON = json.loads(data.decode('utf-8')) + raw = dataJSON[name][price_currency] + price = math.ceil(raw*100) / 100 + change = dataJSON[name]['usd_24h_change'] + + coins.append(self.__build_coin__(name, price, change)) + except: + print("Gecko-Error [" + name + "]") + return coins + + def __build_coin__(self, name, value, change): + coin = CryptoCoin() + + coin.name = self.metadata[name]['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'] + + return coin + + def __prepare_metadata__(self): + 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 } diff --git a/Installer-with-debug.sh b/Installer-with-debug.sh index e4373a6..efa9cbb 100644 --- a/Installer-with-debug.sh +++ b/Installer-with-debug.sh @@ -21,7 +21,7 @@ if [ -z "$option" ]; then fi if [ "$option" = 3 ]; then echo -e "Removing the E-Paper software now..." - pip3 uninstall feedparser -y && sudo pip3 uninstall feedparser -y && pip3 uninstall numpy -y && sudo pip3 uninstall numpy -y && pip3 uninstall Pillow -y && sudo pip3 uninstall Pillow -y && sudo pip3 uninstall pyowm -y&& sudo pip3 uninstall ics -y && pip3 uninstall pyowm -y && pip3 uninstall ics -y && sudo apt-get remove supervisor -y && sudo apt-get clean && sudo apt-get autoremove -y + pip3 uninstall json -y && sudo pip3 uninstall json -y && pip3 uninstall feedparser -y && sudo pip3 uninstall feedparser -y && pip3 uninstall numpy -y && sudo pip3 uninstall numpy -y && pip3 uninstall Pillow -y && sudo pip3 uninstall Pillow -y && sudo pip3 uninstall pyowm -y&& sudo pip3 uninstall ics -y && pip3 uninstall pyowm -y && pip3 uninstall ics -y && sudo apt-get remove supervisor -y && sudo apt-get clean && sudo apt-get autoremove -y if [ -e /etc/supervisor/conf.d/E-Paper.conf ]; then sudo rm /etc/supervisor/conf.d/E-Paper.conf fi @@ -83,10 +83,12 @@ if [ "$option" = 2 ]; then sudo pip3 install ics sudo pip3 install feedparser sudo pip3 install numpy + sudo pip3 install json pip3 install pyowm pip3 install ics pip3 install feedparser pip3 install numpy + pip3 install json echo -e "\e[1;36m"Finished installing libraries"\e[0m" fi -- 2.45.2 From b0ac5504b217f005137c22e4e5a9c638051704c9 Mon Sep 17 00:00:00 2001 From: dicijr Date: Sat, 18 May 2019 19:20:51 -0400 Subject: [PATCH 2/8] Crypto design fix Added 24H change --- Calendar/CryptoListDesign.py | 15 +++++++++------ Calendar/CryptoPrices.py | 7 +++++-- Calendar/settings.py.sample | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) 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", -- 2.45.2 From 2a36a9a6ceb0f5333910eda387516439ccee04f4 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 22:05:49 +0200 Subject: [PATCH 3/8] Implemented availability --- Calendar/GeckoCrypto.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Calendar/GeckoCrypto.py b/Calendar/GeckoCrypto.py index 051c5f7..0a2eed9 100644 --- a/Calendar/GeckoCrypto.py +++ b/Calendar/GeckoCrypto.py @@ -5,7 +5,7 @@ from urllib.request import urlopen import json import math -api_test_url = "https://www.coingecko.com" +api_test_url = "https://api.coingecko.com/api/v3/ping" api_url = "https://api.coingecko.com/api/v3/" api_metadata_url = api_url + "coins/list" api_price_url = api_url + "simple/price" @@ -19,7 +19,6 @@ class GeckoCrypto(CryptoInterface): super(GeckoCrypto, self).__init__() def is_available(self): - return True try: urlopen(api_test_url) return True -- 2.45.2 From b74def5bbf08620389f6bced59f1402b11fd18d8 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 22:06:02 +0200 Subject: [PATCH 4/8] Fine tuned design --- Calendar/CryptoListDesign.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Calendar/CryptoListDesign.py b/Calendar/CryptoListDesign.py index 0efb5bf..40f04ac 100644 --- a/Calendar/CryptoListDesign.py +++ b/Calendar/CryptoListDesign.py @@ -13,7 +13,11 @@ class CryptoListDesign (DesignEntity): def __finish_image__ (self): matrix = self.__get_matrix__() - table_design = TableDesign(self.size, matrix=matrix, col_spacing=5, fontsize = self.text_size, mask=False, truncate_rows=True) + col_spacing = 10 + if len(matrix) > 0: + col_spacing = (self.size[0] / len(matrix[0])) * 0.5 + + table_design = TableDesign(self.size, matrix=matrix, col_spacing=col_spacing, fontsize = self.text_size, mask=False, truncate_rows=True) self.draw_design(table_design) def __get_matrix__ (self): -- 2.45.2 From b58357927f41dd9d6391a5cd6e9734db95a667ba Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 22:08:14 +0200 Subject: [PATCH 5/8] 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 } -- 2.45.2 From ad79095a9ddd2180fb96007b6f75411d22d26048 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 22:20:26 +0200 Subject: [PATCH 6/8] Fine tuned design --- Calendar/CryptoListDesign.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Calendar/CryptoListDesign.py b/Calendar/CryptoListDesign.py index 40f04ac..7a94ba6 100644 --- a/Calendar/CryptoListDesign.py +++ b/Calendar/CryptoListDesign.py @@ -4,6 +4,7 @@ from Assets import defaultfontsize from GeckoCrypto import GeckoCrypto from settings import crypto_coins +xpadding = 5 class CryptoListDesign (DesignEntity): def __init__ (self, size, crypto, text_size = defaultfontsize): @@ -18,6 +19,7 @@ class CryptoListDesign (DesignEntity): col_spacing = (self.size[0] / len(matrix[0])) * 0.5 table_design = TableDesign(self.size, matrix=matrix, col_spacing=col_spacing, fontsize = self.text_size, mask=False, truncate_rows=True) + table_design.pos = (xpadding, 0) self.draw_design(table_design) def __get_matrix__ (self): -- 2.45.2 From 0200116d88ca032f8ee1463bf276dcd5d77e7c69 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 19 May 2019 22:25:59 +0200 Subject: [PATCH 7/8] Implemented crypto interface to panels --- Calendar/AgendaListPanel.py | 5 ++++- Calendar/DayListPanel.py | 5 +++-- Calendar/DayRowDesign.py | 3 --- Calendar/DayViewPanel.py | 4 ++-- Calendar/E-Paper.py | 12 ++++++------ Calendar/MonthOvPanel.py | 3 +++ Calendar/MonthViewPanel.py | 5 ++++- Calendar/PanelDesign.py | 13 ++++++++----- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/Calendar/AgendaListPanel.py b/Calendar/AgendaListPanel.py index 44cd6bf..4bbceb5 100644 --- a/Calendar/AgendaListPanel.py +++ b/Calendar/AgendaListPanel.py @@ -40,7 +40,10 @@ class AgendaListPanel (PanelDesign): self.__draw_seperator__(1-infolist_size[1], colors["fg"]) - def add_taks (self, tasks): + def add_tasks (self, tasks): + pass + + def add_crypto (self, crypto): pass def __finish_panel__(self): diff --git a/Calendar/DayListPanel.py b/Calendar/DayListPanel.py index 6530ce9..7fbb213 100644 --- a/Calendar/DayListPanel.py +++ b/Calendar/DayListPanel.py @@ -51,11 +51,12 @@ class DayListPanel (PanelDesign): self.__draw_rss_infoarea__(rss) def add_crypto (self, crypto): - for row in self.__day_rows__: - row.add_crypto(crypto) if general_settings["info-area"] is "crypto": self.__draw_crypto_infoarea__(crypto) + def add_tasks (self, tasks): + pass + def __draw_rss_infoarea__ (self, rss): height = infoarea_replacedrowscount * self.dayrow_size[1] * self.size[1] - rss_y_padding ypos = self.size[1] - height diff --git a/Calendar/DayRowDesign.py b/Calendar/DayRowDesign.py index 63eac57..7f6d44d 100644 --- a/Calendar/DayRowDesign.py +++ b/Calendar/DayRowDesign.py @@ -37,9 +37,6 @@ class DayRowDesign (DesignEntity): def add_rssfeed (self, rss): pass - - def add_crypto (self, crypto): - pass def __draw_event_list__ (self, calendar): number_width = daynumber_y_size[0] * self.size[1] diff --git a/Calendar/DayViewPanel.py b/Calendar/DayViewPanel.py index 124f21f..512d3a1 100644 --- a/Calendar/DayViewPanel.py +++ b/Calendar/DayViewPanel.py @@ -49,7 +49,7 @@ class DayViewPanel (PanelDesign): self.__draw_rss_feed__(rss) self.__draw_infoarea_line__() - def add_cryptofeed (self, crypto): + def add_crypto (self, crypto): if general_settings["info-area"] == "crypto": self.__draw_crypto_feed__(crypto) self.__draw_infoarea_line__() @@ -90,7 +90,7 @@ class DayViewPanel (PanelDesign): events.pos = pos self.draw_design(events) - def add_taks (self, tasks): + def add_tasks (self, tasks): pass def __finish_panel__ (self): diff --git a/Calendar/E-Paper.py b/Calendar/E-Paper.py index 0745d70..19db1a1 100644 --- a/Calendar/E-Paper.py +++ b/Calendar/E-Paper.py @@ -22,7 +22,7 @@ from AgendaListPanel import AgendaListPanel import OwmForecasts import IcalEvents import RssParserPosts -from GeckoCrypto import GeckoCrypto +import GeckoCrypto all_locales = locale.locale_alias if language.lower() not in all_locales.keys(): @@ -62,7 +62,7 @@ def main(): owm = OwmForecasts.OwmForecasts(location, api_key, paid_api=owm_paid_subscription) events_cal = IcalEvents.IcalEvents(ical_urls, highlighted_ical_urls) rss = RssParserPosts.RssParserPosts(rss_feeds) - crypto = GeckoCrypto(crypto_coins) + crypto = GeckoCrypto.GeckoCrypto(crypto_coins) while True: loop_timer.begin_loop() @@ -78,10 +78,6 @@ def main(): else: raise ImportError("choosen_design must be valid (" + choosen_design + ")") - debug.print_line('Fetching crypto prices from coin gecko') - crypto.reload() - design.add_crypto(crypto) - debug.print_line("Fetching weather information from open weather map") owm.reload() design.add_weather(owm) @@ -94,6 +90,10 @@ def main(): rss.reload() design.add_rssfeed(rss) + debug.print_line('Fetching crypto prices from coin gecko') + crypto.reload() + design.add_crypto(crypto) + debug.print_line("\nStarting to render") for i, output in enumerate(output_adapters): try: diff --git a/Calendar/MonthOvPanel.py b/Calendar/MonthOvPanel.py index b580056..f5be56c 100644 --- a/Calendar/MonthOvPanel.py +++ b/Calendar/MonthOvPanel.py @@ -71,6 +71,9 @@ class MonthOvPanel (PanelDesign): if general_settings["info-area"] is "crypto": self.__draw_crypto_post_list_to_bottom__(crypto) + def add_tasks (self, tasks): + pass + def add_calendar (self, calendar): if general_settings["highlight-event-days"]: month_events = list(set([ (event.begin_datetime.day, event.begin_datetime.month, event.begin_datetime.year) for event in calendar.get_month_events()])) diff --git a/Calendar/MonthViewPanel.py b/Calendar/MonthViewPanel.py index 294520d..c3bc3a7 100644 --- a/Calendar/MonthViewPanel.py +++ b/Calendar/MonthViewPanel.py @@ -74,7 +74,10 @@ class MonthViewPanel (PanelDesign): rss.pos = pos self.draw_design(rss) - def add_taks (self, tasks): + def add_tasks (self, tasks): + pass + + def add_crypto (self, crypto): pass def __finish_panel__(self): diff --git a/Calendar/PanelDesign.py b/Calendar/PanelDesign.py index 53e65dc..361d57c 100644 --- a/Calendar/PanelDesign.py +++ b/Calendar/PanelDesign.py @@ -10,16 +10,19 @@ class PanelDesign (DesignEntity): self.start_timestamp = datetime.now() def add_weather (self, weather): - raise NotImplementedError("Functions needs to be implemented") + raise NotImplementedError("Function needs to be implemented") def add_calendar (self, calendar): - raise NotImplementedError("Functions needs to be implemented") + raise NotImplementedError("Function needs to be implemented") def add_rssfeed (self, rss): - raise NotImplementedError("Functions needs to be implemented") + raise NotImplementedError("Function needs to be implemented") - def add_taks (self, tasks): - raise NotImplementedError("Functions needs to be implemented") + def add_tasks (self, tasks): + raise NotImplementedError("Function needs to be implemented") + + def add_crypto (self, crypto): + raise NotImplementedError("Function needs to be implemented") def __finish_panel__(self): pass -- 2.45.2 From 2269bcf3fa75f0817f27550d6558d6ad68202a3b Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 21 May 2019 14:52:38 +0200 Subject: [PATCH 8/8] Implemented dynamic crypto list in all designs --- Calendar/AgendaListPanel.py | 17 +++++++++++++++-- Calendar/CryptoListDesign.py | 15 ++++++++++----- Calendar/DayListPanel.py | 13 ++++++++----- Calendar/DayViewPanel.py | 3 ++- Calendar/MonthOvPanel.py | 4 +++- Calendar/MonthViewPanel.py | 14 ++++++++++++-- 6 files changed, 50 insertions(+), 16 deletions(-) diff --git a/Calendar/AgendaListPanel.py b/Calendar/AgendaListPanel.py index 4bbceb5..b222d45 100644 --- a/Calendar/AgendaListPanel.py +++ b/Calendar/AgendaListPanel.py @@ -5,12 +5,13 @@ from settings import general_settings, line_thickness from PIL import ImageDraw from Assets import colors from RssPostListDesign import RssPostListDesign +from CryptoListDesign import CryptoListDesign agenda_ypadding = 5 weatherheader_height = 0.113 seperator_width = line_thickness infolist_size = (1, 0.24) -infolist_padding = 2 +infolist_padding = 0 class AgendaListPanel (PanelDesign): '''Lists upcoming events in chronological order and groups them by days''' @@ -44,7 +45,19 @@ class AgendaListPanel (PanelDesign): pass def add_crypto (self, crypto): - pass + if general_settings["info-area"] != "crypto": + return + + self.info_size = self.__abs_pos__(infolist_size) + pos = (0, self.size[1] - self.info_size[1] + infolist_padding) + + list = CryptoListDesign(self.info_size, crypto) + height = list.get_estimated_height() + list.pos = (pos[0], pos[1] + (self.info_size[1] - height)) + self.draw_design(list) + + self.info_size = (self.size[0], height) + self.__draw_seperator__(list.pos[1] / self.size[1], colors["fg"]) def __finish_panel__(self): self.__draw_calendar__() diff --git a/Calendar/CryptoListDesign.py b/Calendar/CryptoListDesign.py index 7a94ba6..949e8a4 100644 --- a/Calendar/CryptoListDesign.py +++ b/Calendar/CryptoListDesign.py @@ -11,14 +11,14 @@ class CryptoListDesign (DesignEntity): super(CryptoListDesign, self).__init__(size) self.crypto = crypto self.text_size = text_size + self.matrix = self.__get_matrix__() def __finish_image__ (self): - matrix = self.__get_matrix__() col_spacing = 10 - if len(matrix) > 0: - col_spacing = (self.size[0] / len(matrix[0])) * 0.5 - - table_design = TableDesign(self.size, matrix=matrix, col_spacing=col_spacing, fontsize = self.text_size, mask=False, truncate_rows=True) + if len(self.matrix) > 0: + col_spacing = (self.size[0] / len(self.matrix[0])) * 0.5 + + table_design = TableDesign(self.size, matrix=self.matrix, col_spacing=col_spacing, fontsize = self.text_size, mask=False, truncate_rows=True) table_design.pos = (xpadding, 0) self.draw_design(table_design) @@ -29,3 +29,8 @@ class CryptoListDesign (DesignEntity): row = [ coin.symbol.upper(), coin.name, coin.currency + " " + str(coin.price), "% " + str(coin.day_change) ] matrix.append(row) return matrix + + def get_estimated_height(self): + line_height = self.text_size * 1.25 + height = line_height * len(self.matrix) + return height diff --git a/Calendar/DayListPanel.py b/Calendar/DayListPanel.py index 7fbb213..e271208 100644 --- a/Calendar/DayListPanel.py +++ b/Calendar/DayListPanel.py @@ -10,6 +10,7 @@ from DayRowDesign import DayRowDesign from RssPostListDesign import RssPostListDesign from CryptoListDesign import CryptoListDesign from settings import line_thickness +from math import ceil todayheader_pos = (0,0) todayheader_size = (1,0.25) @@ -48,6 +49,7 @@ class DayListPanel (PanelDesign): for row in self.__day_rows__: row.add_rssfeed(rss) if general_settings["info-area"] is "rss": + self.__day_rows__ = self.__day_rows__[:-infoarea_replacedrowscount] self.__draw_rss_infoarea__(rss) def add_crypto (self, crypto): @@ -74,8 +76,12 @@ class DayListPanel (PanelDesign): pos = (0, ypos) design = CryptoListDesign(size, crypto) - design.pos = pos + acutal_height = design.get_estimated_height() + design.pos = (pos[0], pos[1] + (height - acutal_height)) self.draw_design(design) + + replaced_rows = ceil(acutal_height / (self.dayrow_size[1] * self.size[1])) + self.__day_rows__ = self.__day_rows__[:-replaced_rows] def __draw_day_rows__ (self): following_days = self.__get_following_days__() @@ -98,9 +104,6 @@ class DayListPanel (PanelDesign): row_height = max_area_height / self.dayrow_count self.dayrow_size = (1, row_height / self.size[1]) - if general_settings["info-area"] in ["rss"] or ["crypto"]: - self.dayrow_count -= infoarea_replacedrowscount - def __get_following_days__(self): following_days = [] for i in range(self.dayrow_count): @@ -114,7 +117,7 @@ class DayListPanel (PanelDesign): def __draw_lines__(self): positions = [] - for i in range(self.dayrow_count + 1): + for i in range(len(self.__day_rows__)): positions.append(self.__get_day_row_pos__(i)[1]) for ypos in positions: line_start = (0, ypos) diff --git a/Calendar/DayViewPanel.py b/Calendar/DayViewPanel.py index 512d3a1..a35447c 100644 --- a/Calendar/DayViewPanel.py +++ b/Calendar/DayViewPanel.py @@ -77,7 +77,8 @@ class DayViewPanel (PanelDesign): pos = (0, self.size[1] - size[1]) crypto = CryptoListDesign(size, crypto) - crypto.pos = pos + acutal_height = crypto.get_estimated_height() + crypto.pos = (pos[0], pos[1] + (height - acutal_height)) self.draw_design(crypto) diff --git a/Calendar/MonthOvPanel.py b/Calendar/MonthOvPanel.py index f5be56c..b377a32 100644 --- a/Calendar/MonthOvPanel.py +++ b/Calendar/MonthOvPanel.py @@ -95,8 +95,10 @@ class MonthOvPanel (PanelDesign): month_pos = self.__abs_pos__(monthovposition) month_height = self.month_block.get_real_height() size = (self.size[0], self.size[1] - (month_pos[1] + month_height + self.weather_header_height)) + info_list = CryptoListDesign(size, crypto) - info_list.pos = (int(month_pos[0]), month_pos[1] + month_height + self.weather_header_height) + list_height = info_list.get_estimated_height() + info_list.pos = (int(month_pos[0]), month_pos[1] + month_height + self.weather_header_height + (size[1] - list_height)) self.draw_design(info_list) def __draw_event_list_to_bottom__ (self, calendar): diff --git a/Calendar/MonthViewPanel.py b/Calendar/MonthViewPanel.py index c3bc3a7..4fbab24 100644 --- a/Calendar/MonthViewPanel.py +++ b/Calendar/MonthViewPanel.py @@ -8,6 +8,7 @@ from TableDesign import TableDesign from DayBoxDesign import DayBoxDesign from RssPostListDesign import RssPostListDesign from WeatherHeaderDesign import WeatherHeaderDesign +from CryptoListDesign import CryptoListDesign weather_height = 0.113 info_height = 0.25 @@ -32,7 +33,7 @@ class MonthViewPanel (PanelDesign): def __init_sizes__(self): self.weather_height = 0 self.info_height = 0 - if general_settings["info-area"] in ["events", "rss"]: + if general_settings["info-area"] in ["events", "rss", "crypto"]: self.info_height = info_height if general_settings["weather-info"]: self.weather_height = weather_height @@ -78,7 +79,16 @@ class MonthViewPanel (PanelDesign): pass def add_crypto (self, crypto): - pass + if general_settings["info-area"] == "crypto": + self.__draw_crypto__(crypto) + + def __draw_crypto__(self, crypto): + size = (self.size[0], self.size[1] * self.info_height) + pos = (0, self.size[1] - size[1]) + + crypto = CryptoListDesign(size, crypto) + crypto.pos = (pos[0],pos[1] + (size[1] - crypto.get_estimated_height())) + self.draw_design(crypto) def __finish_panel__(self): self.__draw_days__() -- 2.45.2