Last active
August 29, 2015 14:07
-
-
Save dansloane/8bbdedb033cddf1aedb7 to your computer and use it in GitHub Desktop.
Caxton Pre-paid card XLS (actually HTML) to Xero import
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
| #!/usr/bin/python | |
| # caxton2xero.py | |
| # converts a Caxton Pre-paid card statement to CSV for Xero upload | |
| # dms/ssq/29.09.2014 | |
| # Caxton pre-paid Visa card only have 'XLS' output, which is actually HTML | |
| # Xero can import statements using QIF or CSV in a particular format | |
| # http://help.xero.com/help/bankaccounts_details_importtranscsv.htm | |
| # | |
| # This script uses BeautifulSoup to parse the HTML and CSV to output the | |
| # relevant fields as required by the Xero spec above. | |
| from bs4 import BeautifulSoup | |
| import sys | |
| import re | |
| import csv | |
| import string | |
| def cell_text(cell): | |
| return " ".join(cell.stripped_strings) | |
| soup = BeautifulSoup(sys.stdin.read()) | |
| output = csv.writer(sys.stdout,quoting=csv.QUOTE_NONNUMERIC,delimiter=',') | |
| xeroheader = ['Date','Amount','Payee','Description'] | |
| output.writerow(xeroheader) | |
| for table in soup.find_all('tbody'): | |
| for row in table.find_all('tr'): | |
| transdate = row.find_all('td')[0].string | |
| transdate = transdate.split()[0] | |
| transvalue = row.find_all('td')[6].string | |
| transvalue = float(transvalue) * -1 | |
| payee = row.find_all('td')[1].string | |
| description = "Local currency = " + row.find_all('td')[2].string | |
| op = [transdate,transvalue,payee,description] | |
| output.writerow(op) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment