Guest User

Untitled

a guest
Jan 10th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 1,
  6. "metadata": {},
  7. "outputs": [],
  8. "source": [
  9. "from __future__ import absolute_import, print_function\n",
  10. "\n",
  11. "import itertools as it\n",
  12. "from meza.io import read_csv, IterStringIO\n",
  13. "from meza import io, process, convert\n",
  14. "from csv2ofx import utils\n",
  15. "from csv2ofx.ofx import OFX\n",
  16. "from operator import itemgetter\n"
  17. ]
  18. },
  19. {
  20. "cell_type": "code",
  21. "execution_count": 2,
  22. "metadata": {},
  23. "outputs": [],
  24. "source": [
  25. "\n",
  26. "# Date\t\n",
  27. "# Native Amount\t\n",
  28. "# Native Currency\t\n",
  29. "# Billed Amount\t\n",
  30. "# Billed Currency\n",
  31. "# Has Folio\t\n",
  32. "# Merchant\t\n",
  33. "# City\t\n",
  34. "# Card Type\t\n",
  35. "# Personal Card\t\n",
  36. "# Card Account\n",
  37. "i = 0\n",
  38. "mapping = {\n",
  39. " 'has_header': True, \n",
  40. " 'is_split': False, \n",
  41. " 'bank': 'Bank', \n",
  42. " 'delimiter': ',',\n",
  43. " 'date': itemgetter('Date'),\n",
  44. " 'currency': itemgetter('Type Foreign Currency'),\n",
  45. " 'account': 'N26 Auto Import', \n",
  46. " 'amount': lambda tr: tr['Amount (Foreign Currency)'] or tr['Amount (EUR)'], \n",
  47. " 'desc': lambda tr: 'EUR charged:' + tr['Amount (EUR)'], \n",
  48. " 'notes': lambda tr: 'EUR charged:' + tr['Amount (EUR)'], \n",
  49. " 'payee': itemgetter('Payee'), \n",
  50. " 'id': 1\n",
  51. "}\n"
  52. ]
  53. },
  54. {
  55. "cell_type": "code",
  56. "execution_count": 3,
  57. "metadata": {},
  58. "outputs": [],
  59. "source": [
  60. "ofx = OFX(mapping)"
  61. ]
  62. },
  63. {
  64. "cell_type": "code",
  65. "execution_count": 4,
  66. "metadata": {},
  67. "outputs": [],
  68. "source": [
  69. "records = read_csv('/Users/jfinlays/Downloads/20171105-20171228.csv')"
  70. ]
  71. },
  72. {
  73. "cell_type": "code",
  74. "execution_count": 5,
  75. "metadata": {},
  76. "outputs": [],
  77. "source": [
  78. "groups = ofx.gen_groups(records)\n",
  79. "trxns = ofx.gen_trxns(groups)\n"
  80. ]
  81. },
  82. {
  83. "cell_type": "code",
  84. "execution_count": 6,
  85. "metadata": {},
  86. "outputs": [],
  87. "source": [
  88. "cleaned_trxns = ofx.clean_trxns(trxns)\n",
  89. "data = utils.gen_data(cleaned_trxns)\n",
  90. "content = it.chain([ofx.header(), ofx.gen_body(data), ofx.footer()])\n",
  91. "\n",
  92. "lines = list(IterStringIO(content))\n",
  93. "\n",
  94. "with open('out.ofx', \"wb\" ) as file:\n",
  95. " file.writelines(lines)\n",
  96. "\n"
  97. ]
  98. }
  99. ],
  100. "metadata": {
  101. "kernelspec": {
  102. "display_name": "Python 3",
  103. "language": "python",
  104. "name": "python3"
  105. },
  106. "language_info": {
  107. "codemirror_mode": {
  108. "name": "ipython",
  109. "version": 3
  110. },
  111. "file_extension": ".py",
  112. "mimetype": "text/x-python",
  113. "name": "python",
  114. "nbconvert_exporter": "python",
  115. "pygments_lexer": "ipython3",
  116. "version": "3.6.0"
  117. }
  118. },
  119. "nbformat": 4,
  120. "nbformat_minor": 2
  121. }
Add Comment
Please, Sign In to add comment