Skip to content

Instantly share code, notes, and snippets.

@olivierlemoal
Last active November 16, 2015 20:46
Show Gist options
  • Save olivierlemoal/44f193d9c3c7de8b2275 to your computer and use it in GitHub Desktop.
Save olivierlemoal/44f193d9c3c7de8b2275 to your computer and use it in GitHub Desktop.
Convert Boursorama csv export -> YNAB csv
#! /usr/bin/env python3
import sys
import csv
from collections import defaultdict
def parse_input(inputFile):
lines = defaultdict(list)
with open(inputFile, newline='', encoding='iso8859-15') as csvfile:
inputReader = csv.reader(csvfile, delimiter=';', quotechar='"')
next(inputReader) # Skip header
for row in inputReader:
lines[row[6]].append((row[0], row[2], row[3], row[4]))
return lines
def write_output(lines):
for account in lines.keys():
to_export = lines[account]
outputFile = account + ".csv"
with open(outputFile, "w", newline='', encoding='utf8') as csvfile:
outputWriter = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
header = ("Date", "Payee", "Category", "Memo", "Outflow", "Inflow")
outputWriter.writerow(header)
for line in to_export:
if "-" not in line[3]:
outputWriter.writerow((line[0], line[1], line[2], "", "", line[3]))
else:
outputWriter.writerow((line[0], line[1], line[2], "", line[3].replace("-", ""), ""))
def main():
if len(sys.argv) < 1:
print("Usage :")
print("{} input_csv".format(sys.argv[0]))
exit(1)
inputFile = sys.argv[1]
lines = parse_input(inputFile)
write_output(lines)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment