Loading proofofbrain-blog...

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.

image.png
image.png
Hive.blog export

image.png
image.png
Cointracking Import

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

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.

Untitled design.png

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 Library
import pandas as pd
#read csv into raw var
raw = pd.read_csv('hive-report.csv')
#Drop unneeded columns
raw.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 columns
raw.rename(columns={'timestamp': 'Date',' opType': 'Type',' amount': 'Buy Amount' }, inplace=True)
#Remove unneeded transaction types
remove_types = raw[raw["Type"].str.contains(" curation_reward| author_reward| comment_reward")==False]
#Arrange types in proper order
arrange_types = remove_types[['Type','Buy Amount', 'Date']]
#Replace transfer with deposit
arrange_types['Type'] = arrange_types['Type'].replace([' transfer'], 'Income')
#Strip whitespace from Buy Amount
arrange_types['Buy Amount'] = arrange_types['Buy Amount'].str.lstrip()
#Split price from currency
arrange_types[['Buy Amount','Buy Currency']] = arrange_types['Buy Amount'].str.split(' ', 1, expand=True)
#Rearrange columns
arrange_types = arrange_types[['Type','Buy Amount', 'Buy Currency', 'Date']]
#Insert required columns for Cointracking
arrange_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 comments
arrange_types.loc[:,'Exchange'] = 'HIVE WALLET'
arrange_types.loc[:,'Trade-Group'] = 'HIVE CSV'
arrange_types.loc[:,'Comment'] = 'Delegation Income'
#Remove T character from date
arrange_types['Date'] = arrange_types['Date'].str.replace('T', ' ')
#Save to a new csv
arrange_types.to_csv('hive-report2.csv', index=False)

Untitled design.png

Proof of Work

image.png
image.png

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

Untitled design.png

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.

H2
H3
H4
3 columns
2 columns
1 column
6 Comments