Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [],
- "source": [
- "from __future__ import absolute_import, print_function\n",
- "\n",
- "import itertools as it\n",
- "from meza.io import read_csv, IterStringIO\n",
- "from meza import io, process, convert\n",
- "from csv2ofx import utils\n",
- "from csv2ofx.ofx import OFX\n",
- "from operator import itemgetter\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [],
- "source": [
- "\n",
- "# Date\t\n",
- "# Native Amount\t\n",
- "# Native Currency\t\n",
- "# Billed Amount\t\n",
- "# Billed Currency\n",
- "# Has Folio\t\n",
- "# Merchant\t\n",
- "# City\t\n",
- "# Card Type\t\n",
- "# Personal Card\t\n",
- "# Card Account\n",
- "i = 0\n",
- "mapping = {\n",
- " 'has_header': True, \n",
- " 'is_split': False, \n",
- " 'bank': 'Bank', \n",
- " 'delimiter': ',',\n",
- " 'date': itemgetter('Date'),\n",
- " 'currency': itemgetter('Type Foreign Currency'),\n",
- " 'account': 'N26 Auto Import', \n",
- " 'amount': lambda tr: tr['Amount (Foreign Currency)'] or tr['Amount (EUR)'], \n",
- " 'desc': lambda tr: 'EUR charged:' + tr['Amount (EUR)'], \n",
- " 'notes': lambda tr: 'EUR charged:' + tr['Amount (EUR)'], \n",
- " 'payee': itemgetter('Payee'), \n",
- " 'id': 1\n",
- "}\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [],
- "source": [
- "ofx = OFX(mapping)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [],
- "source": [
- "records = read_csv('/Users/jfinlays/Downloads/20171105-20171228.csv')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "groups = ofx.gen_groups(records)\n",
- "trxns = ofx.gen_trxns(groups)\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "cleaned_trxns = ofx.clean_trxns(trxns)\n",
- "data = utils.gen_data(cleaned_trxns)\n",
- "content = it.chain([ofx.header(), ofx.gen_body(data), ofx.footer()])\n",
- "\n",
- "lines = list(IterStringIO(content))\n",
- "\n",
- "with open('out.ofx', \"wb\" ) as file:\n",
- " file.writelines(lines)\n",
- "\n"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.6.0"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment