View full version

Making the Hive Blog Wallet Financial Report Useable in Cointracking with Python/Pandas/Jupyter

The Problem

A few posts ago, I complained about the inability to import certain HIVE wallet transactions into Cointracking. Rather than manually hack at another spreadsheet after January, I decided to try my hand at automating it. What I needed was a way to translate the CSV file that the Hive.blog wallet spits out to a format that Cointracking recognizes.



Hive.blog export



Cointracking Import

As you can see, the CSV formats don't match at all, and unfortunately Cointracking doesn't have native Hive support.

My Solution

First off, I am not a developer. At best I'm a coding hack. If you developers know of a easier way to refactor this, I'm all 'ears'. For my solution, I decided to use Python with Jupyter notebook and the Pandas library. Jupyter notebook is great for hacks like me by the way. You can run all of this yourself by downloading the Anaconda Personal Edition for free (https://www.anaconda.com/products/individual).

The steps I took went basically like this.

  • Download a copy of my Hive transaction history and load it into a Pandas data frame.
  • Drop any columns from the Hive wallet output I didn't need
  • Rename the remaining columns to make them Cointracking compliant
  • Remove any rows from the transaction types that require claiming (curation, author, and comment rewards)
  • Arrange the rows in the proper order to make them Cointracking compliant
  • Insert any columns required by Cointracking (Whether they get populated or not)
  • Populate any necessary columns (Exchange, Trade-Group, Comment)
  • Split the 'amount' column into two new columns ('Buy Amount' & 'Buy Currency')
  • Any required formatting, such as removing whitespace and the 'T' from the Date/timestamp.

The Code

Here is the code I used. I got lazy with the variable I used for my data frame, but you should get the idea. I will probably work to make it more intuitive. The good news I could get everything I needed done with just the Pandas libary.

#Import the Pandas Libraryimport pandas as pd#read csv into raw varraw = pd.read_csv('hive-report.csv')#Drop unneeded columnsraw.drop(columns=[' comment_author',' comment_permlink',' author',' permlink', ' curator', ' payout_must_be_claimed',' reward',' memo',' hbd_payout'], inplace=True)raw.drop(columns=[' hive_payout',' vesting_payout',' payout',' to',' from' ], inplace=True)#Rename needed columnsraw.rename(columns={'timestamp': 'Date',' opType': 'Type',' amount': 'Buy Amount' }, inplace=True)#Remove unneeded transaction typesremove_types = raw[raw["Type"].str.contains(" curation_reward| author_reward| comment_reward")==False]#Arrange types in proper orderarrange_types = remove_types[['Type','Buy Amount', 'Date']]#Replace transfer with depositarrange_types['Type'] = arrange_types['Type'].replace([' transfer'], 'Income')#Strip whitespace from Buy Amountarrange_types['Buy Amount'] = arrange_types['Buy Amount'].str.lstrip()#Split price from currencyarrange_types[['Buy Amount','Buy Currency']] = arrange_types['Buy Amount'].str.split(' ', 1, expand=True)#Rearrange columnsarrange_types = arrange_types[['Type','Buy Amount', 'Buy Currency', 'Date']]#Insert required columns for Cointrackingarrange_types.insert(3,'Sell Amount','')arrange_types.insert(4,'Sell Currency','')arrange_types.insert(5,'Fee','')arrange_types.insert(6,'Fee Currency','')arrange_types.insert(7,'Exchange','')arrange_types.insert(8,'Trade-Group','')arrange_types.insert(9,'Comment','')#Assign values for exchange, trade-group, and commentsarrange_types.loc[:,'Exchange'] = 'HIVE WALLET'arrange_types.loc[:,'Trade-Group'] = 'HIVE CSV'arrange_types.loc[:,'Comment'] = 'Delegation Income'#Remove T character from datearrange_types['Date'] = arrange_types['Date'].str.replace('T', ' ')#Save to a new csvarrange_types.to_csv('hive-report2.csv', index=False)

Proof of Work


As you can see above, the CSV I generated was property formatted and successfully imported into cointracking.

Conclusion

This was a fun exercise for me. I'm not a developer (obviously). The good news is I can use similar steps for other Exchanges and wallets that export CSV files that Cointracking doesn't support. I will not have to hack at spreadsheets every month for various transactions exports. If any Python/Pandas experts out there read this, please do critique my work. Obviously this is functional, but I would be interested to know if there is a more efficient way of performing the same work. If you were dying for a way to record HIVE deposits, please feel free to use this and let me know if you have any questions.