Created
January 30, 2015 01:48
-
-
Save gautamk/6b7f8ddb84b07f30643d to your computer and use it in GitHub Desktop.
Convert One Touch Expenser export csv to Monas import csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from datetime import datetime | |
with open('expenses.csv','r') as input_csv_file: | |
csv_reader =csv.DictReader(input_csv_file,fieldnames=['Date','Amount','Note','Tag'], delimiter=';') | |
csv_reader.next() | |
with open('monas.csv','w') as output_csv_file: | |
output_csv_file.write('"Date (MM/DD/YYYY)","Category","Amount","Note"\n') | |
writer = csv.DictWriter(output_csv_file, | |
fieldnames=["Date (MM/DD/YYYY)","Category","Amount","Note"],quotechar='"') | |
for row in csv_reader: | |
parsed_date = datetime.strptime(row['Date'],"%d/%m/%Y") | |
row['Date'] = datetime.strftime(parsed_date,"%m/%d/%Y") | |
row['Amount'] = str(float(row['Amount']) * -1) | |
if not row['Tag']: | |
row['Tag'] = "wasted" | |
output_dict = { | |
"Date (MM/DD/YYYY)":row['Date'], | |
"Category":row['Tag'], | |
"Amount":row['Amount'], | |
"Note":row['Note'] | |
} | |
writer.writerow(output_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment