From 108da45e53b104d28f65e587f741ca104ec3593d Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 5 Dec 2012 22:42:40 +0100 Subject: [PATCH 1/4] Added the option to export your transactions to a CSV file --- lib/gui_lite.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/gui_lite.py b/lib/gui_lite.py index 5563737b..72e5fb8e 100644 --- a/lib/gui_lite.py +++ b/lib/gui_lite.py @@ -28,7 +28,10 @@ import wallet import webbrowser import history_widget import util +import csv +import datetime +from wallet import format_satoshis import gui_qt import shutil @@ -254,6 +257,9 @@ class MiniWindow(QDialog): backup_wallet = extra_menu.addAction( _("&Create wallet backup")) backup_wallet.triggered.connect(self.backup_wallet) + export_csv = extra_menu.addAction( _("&Export transactions to CSV") ) + export_csv.triggered.connect(self.actuator.csv_transaction) + expert_gui = view_menu.addAction(_("&Classic GUI")) expert_gui.triggered.connect(expand_callback) themes_menu = view_menu.addMenu(_("&Themes")) @@ -732,6 +738,42 @@ class MiniActuator: w.exec_() w.destroy() + def csv_transaction(self): + try: + fileName = QFileDialog.getSaveFileName(QWidget(), 'Select file to export your wallet transactions to', os.path.expanduser('~/'), "*.csv") + if fileName: + with open(fileName, "w+") as csvfile: + transaction = csv.writer(csvfile) + transaction.writerow(["transaction_hash","label", "confirmations", "value", "fee", "balance", "timestamp"]) + for item in self.wallet.get_tx_history(): + tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item + if confirmations: + try: + time_string = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] + except [RuntimeError, TypeError, NameError] as reason: + print reason + time_string = "unknown" + else: + time_string = "pending" + + if value is not None: + value_string = format_satoshis(value, True, self.wallet.num_zeros) + else: + value_string = '--' + + if fee is not None: + fee_string = format_satoshis(fee, True, self.wallet.num_zeros) + else: + fee_string = '0' + + if tx_hash: + label, is_default_label = self.wallet.get_label(tx_hash) + balance_string = format_satoshis(balance, False, self.wallet.num_zeros) + transaction.writerow([tx_hash, label, confirmations, value_string, fee_string, balance_string, time_string]) + QMessageBox.information(None,"CSV Export created", "Your CSV export has been succesfully created.") + except (IOError, os.error), reason: + QMessageBox.critical(None,"Unable to create csv", "Electrum was unable to produce a transaction export.\n" + str(reason)) + def send(self, address, amount, parent_window): """Send bitcoins to the target address.""" dest_address = self.fetch_destination(address) From c50103870e4fc26743da5a9770c29df74b70e14a Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 5 Dec 2012 22:55:15 +0100 Subject: [PATCH 2/4] Handle exceptions on parsing better --- lib/gui_lite.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/gui_lite.py b/lib/gui_lite.py index 72e5fb8e..f1c8dadd 100644 --- a/lib/gui_lite.py +++ b/lib/gui_lite.py @@ -748,11 +748,12 @@ class MiniActuator: for item in self.wallet.get_tx_history(): tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item if confirmations: - try: - time_string = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] - except [RuntimeError, TypeError, NameError] as reason: - print reason - time_string = "unknown" + if timestamp is not None: + try: + time_string = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] + except [RuntimeError, TypeError, NameError] as reason: + time_string = "unknown" + pass else: time_string = "pending" From 9083be46f74564dcad526fc9cc9dd810351f7e5b Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 5 Dec 2012 23:04:16 +0100 Subject: [PATCH 3/4] There isn't always a tx hash..\? --- lib/gui_lite.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/gui_lite.py b/lib/gui_lite.py index f1c8dadd..e0e26ffa 100644 --- a/lib/gui_lite.py +++ b/lib/gui_lite.py @@ -769,6 +769,9 @@ class MiniActuator: if tx_hash: label, is_default_label = self.wallet.get_label(tx_hash) + else: + label = "" + balance_string = format_satoshis(balance, False, self.wallet.num_zeros) transaction.writerow([tx_hash, label, confirmations, value_string, fee_string, balance_string, time_string]) QMessageBox.information(None,"CSV Export created", "Your CSV export has been succesfully created.") From 9bf12079ce3b7481b56c9d66529dcf8f7ba5821e Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 5 Dec 2012 23:18:31 +0100 Subject: [PATCH 4/4] Added default time string --- lib/gui_lite.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/gui_lite.py b/lib/gui_lite.py index e0e26ffa..d2f61063 100644 --- a/lib/gui_lite.py +++ b/lib/gui_lite.py @@ -750,10 +750,12 @@ class MiniActuator: if confirmations: if timestamp is not None: try: - time_string = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3] + time_string = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3] except [RuntimeError, TypeError, NameError] as reason: time_string = "unknown" pass + else: + time_string = "unknown" else: time_string = "pending"