summaryrefslogtreecommitdiff
path: root/invest-applet/invest/quotes.py
diff options
context:
space:
mode:
authorinfirit <[email protected]>2015-01-04 22:57:25 +0100
committerinfirit <[email protected]>2015-01-05 00:17:21 +0100
commit14ad0b4e9311e090865e3d613970bdc5b54ef274 (patch)
tree4dee29a2ce18c26747397bd80748d42279cc584f /invest-applet/invest/quotes.py
parent30a5f1e62ac9d12deef0c3ccf7f84b71b7f8ee41 (diff)
downloadmate-applets-14ad0b4e9311e090865e3d613970bdc5b54ef274.tar.bz2
mate-applets-14ad0b4e9311e090865e3d613970bdc5b54ef274.tar.xz
invest: Add saving and loading of currency conversion data
fixes #119
Diffstat (limited to 'invest-applet/invest/quotes.py')
-rw-r--r--invest-applet/invest/quotes.py34
1 files changed, 28 insertions, 6 deletions
diff --git a/invest-applet/invest/quotes.py b/invest-applet/invest/quotes.py
index d9bdb6b1..4fba6bfa 100644
--- a/invest-applet/invest/quotes.py
+++ b/invest-applet/invest/quotes.py
@@ -86,14 +86,14 @@ class QuoteUpdater(Gtk.ListStore):
self.change_icon_callback = change_icon_callback
self.set_tooltip_callback = set_tooltip_callback
self.set_sort_column_id(1, Gtk.SortType.ASCENDING)
- self.load() # read the last cached quotes file
+ self.load_quotes() # read the last cached quotes file
self.refresh() # download a new quotes file, this may fail if disconnected
# tell the network manager to notify me when network status changes
mate_invest.nm.set_statechange_callback(self.nm_state_changed)
# loads the cached csv file and its last-modification-time as self.last_updated
- def load(self):
+ def load_quotes(self):
mate_invest.debug("Loading quotes");
try:
f = open(mate_invest.QUOTES_FILE, 'r')
@@ -108,7 +108,7 @@ class QuoteUpdater(Gtk.ListStore):
mate_invest.error("Could not load the cached quotes file %s: %s" % (mate_invest.QUOTES_FILE, msg) )
# stores the csv content on disk so it can be used on next start up
- def save(self, data):
+ def save_quotes(self, data):
mate_invest.debug("Storing quotes")
try:
f = open(mate_invest.QUOTES_FILE, 'w')
@@ -173,17 +173,39 @@ class QuoteUpdater(Gtk.ListStore):
else:
mate_invest.debug("QuotesRetriever completed");
# cache the retrieved csv file
- self.save(retriever.data)
+ self.save_quotes(retriever.data)
# load the cache and parse it
- self.load()
+ self.load_quotes()
def on_currency_retriever_completed(self, retriever):
if retriever.retrieved == False:
mate_invest.error("Failed to retrieve currency rates!")
else:
- self.convert_currencies(self.parse_yahoo_csv(csv.reader(retriever.data)))
+ mate_invest.debug("CurrencyRetriever completed")
+ self.save_currencies(retriever.data)
+ self.load_currencies()
self.update_tooltip()
+ def save_currencies(self, data):
+ mate_invest.debug("Storing currencies to %s" % mate_invest.CURRENCIES_FILE)
+ try:
+ f = open(mate_invest.CURRENCIES_FILE, 'w')
+ f.write(data)
+ f.close()
+ except Exception as msg:
+ mate_invest.error("Could not save the retrieved currencies to %s: %s" % (mate_invest.CURRENCIES_FILE, msg) )
+
+ def load_currencies(self):
+ mate_invest.debug("Loading currencies from %s" % mate_invest.CURRENCIES_FILE)
+ try:
+ f = open(mate_invest.CURRENCIES_FILE, 'r')
+ data = f.readlines()
+ f.close()
+
+ self.convert_currencies(self.parse_yahoo_csv(csv.reader(data)))
+ except Exception as msg:
+ mate_invest.error("Could not load the currencies from %s: %s" % (mate_invest.CURRENCIES_FILE, msg) )
+
def update_tooltip(self, msg = None):
tooltip = []
if self.quotes_count > 0: