rienafairefr / pynYNAB

a python client for the new YNAB
MIT License
138 stars 12 forks source link

Allow importing via CSV #2

Closed scottrobertson closed 8 years ago

scottrobertson commented 8 years ago

Being able to import via a CSV would be incredible. Even something as simple as the following:

date payee amount memo account
2015-01-01 Amazon 100 Something something Mondo
rienafairefr commented 8 years ago

I've implemented a CSV importer script, can you test it with your data?

scottrobertson commented 8 years ago

Awesome! Shall do. How are you thinking of dealing with duplicates?

scottrobertson commented 8 years ago
Traceback (most recent call last):
  File "scripts/csvimport.py", line 6, in <module>
    from jsontableschema.model import SchemaModel
  File "/usr/local/lib/python2.7/site-packages/jsontableschema-0.5.1-py2.7.egg/jsontableschema/__init__.py", line 7, in <module>
    from . import exceptions
  File "/usr/local/lib/python2.7/site-packages/jsontableschema-0.5.1-py2.7.egg/jsontableschema/exceptions.py", line 7, in <module>
    import jsonschema.exceptions
  File "/usr/local/lib/python2.7/site-packages/jsonschema-2.5.1-py2.7.egg/jsonschema/__init__.py", line 12, in <module>
    from jsonschema.exceptions import (
  File "/usr/local/lib/python2.7/site-packages/jsonschema-2.5.1-py2.7.egg/jsonschema/exceptions.py", line 6, in <module>
    from jsonschema import _utils
  File "/usr/local/lib/python2.7/site-packages/jsonschema-2.5.1-py2.7.egg/jsonschema/_utils.py", line 6, in <module>
    from jsonschema.compat import str_types, MutableMapping, urlsplit
  File "/usr/local/lib/python2.7/site-packages/jsonschema-2.5.1-py2.7.egg/jsonschema/compat.py", line 39, in <module>
    from functools32 import lru_cache
ImportError: No module named functools32
rienafairefr commented 8 years ago

For now, duplicates are imported as is, no effort to remove them. I will try to not import a transaction if a matching one already exists in nYNAB (same date, amount, category, memo etc).

I think the error you get is due to an old version of pip or setuptools, during jsontableschema install the functools32 dependency is not installed, just install it manually (pip install functools32)

scottrobertson commented 8 years ago

For now, duplicates are imported as is, no effort to remove them. I will try to not import a transaction if a matching one already exists in nYNAB (same date, amount, category, memo etc).

That would be perfect. Just very basic checking is enough :)

I think the error you get is due to an old version of pip or setuptools, during jsontableschema install the functools32 dependency is not installed, just install it manually (pip install functools32)

Just installed it via brew. Shall try and install it manually and see. Man, there must be a better way for python to handle this stuff. Like a Gemfile :P

rienafairefr commented 8 years ago

duplicates should be handled now, see commit

rienafairefr commented 8 years ago

python setup.py install is the way python handle this stuff, that should work ^^

scottrobertson commented 8 years ago

Thank you. Getting pynYNAB.Client.BudgetNotFound now. Tried the name, ID etc

scottrobertson commented 8 years ago

Ok, sorted that. They are all "My Budget" for some reason.

Traceback (most recent call last):
  File "scripts/csvimport.py", line 39, in <module>
    get_logger().ERROR('This schema doesn''t exist in csv_schemas')
  File "build/bdist.macosx-10.11-x86_64/egg/pynYNAB/config.py", line 20, in get_logger
AttributeError: 'NoneType' object has no attribute 'upper'

Is my next issue. I am using --schema=example

rienafairefr commented 8 years ago

Hi Scott, I've sorted a bit the scripts interface, see scripts/README.rst for the documentation. while in the scripts folder I think now you can do:

python csvmport.py data.csv example

"My Budget" default and logger level being None was a bug.

scottrobertson commented 8 years ago
Traceback (most recent call last):
  File "scripts/csvimport.py", line 10, in <module>
    from pynYNAB.Client import clientfromargs
ImportError: cannot import name clientfromargs
rienafairefr commented 8 years ago

did you get and install the new source? If you want to be able to git pull for the package and get it system wide easily, you can use do python setup.py develop

scottrobertson commented 8 years ago

I did a git pull, but could not run python setup.py develop. I posted in the other ticket about that, as it throws an error.

rienafairefr commented 8 years ago

Indeed, there was a bug in setup.py (I had changed the README name markup), it's fixed now. Sorry about that

scottrobertson commented 8 years ago

Seems to run ok now, but it's not inserting anything into YNAB

scottrobertson commented 8 years ago

Looking at the JSON response in YNAB, all of my budgets are named "my budget" for some reason... very odd. Perhaps it's because i created them way back in the beta.

rienafairefr commented 8 years ago

I know at some point pynYNAB defaulted to 'My Budget' for the budget name. If you want to insert in another budget specify it in ynab.conf or add --budgetname YourBudgetNamee to the call to csvimport script. Can you paste here a snippet of the csv data, the full command line for the call to csvimport.py, and the ynab.conf (put ****\ where your ID/password is) if applicable

scottrobertson commented 8 years ago

Well, the actual budget name is "Scott's Budget" in YNAB's interface, but not in the JSON oddly.

python pynYNAB/scripts/csvimport.py ~/Downloads/ynab.csv example --email=**** --password=**** --budget='My Budget'

2016-03-08, Testing, 10, Something, Mondo
rienafairefr commented 8 years ago

I've documented the usage in the documentation,

usage: csvimport.py [-h] [--email Email] [--password Password]
                    [--level LoggingLevel] [--budgetname BudgetName]
                    CSVpath schemaName [AccountName]

I think the correct call in your case would be:

python pynYNAB/scripts/csvimport.py ~/Downloads/ynab.csv example --email * --password ** --budgetname "Scott's Budget"

scottrobertson commented 8 years ago

It seems to find the budget ok with My Budget. If i use Scott's Budget it breaks.

No budget by this name found in nYNAB

scottrobertson commented 8 years ago

Perhaps print each transaction out that will be added to be_transactions

scottrobertson commented 8 years ago

error: python-dateutil 2.5.0 is installed but python-dateutil<=2.4.2 is required by set(['dateparser'])

Getting that now when running setup. What is the best way to deal with that?

rienafairefr commented 8 years ago

I used dateparser dependency before I think, not anymore, so I removed it. I guess something else is installed on your system that needed python-dateutil 2.5.0 . You could use a virtualenv to install pynYNAB in isolation but I think that's overkill.

scottrobertson commented 8 years ago

Ah ok. So is it safe to just ignore that?

Anyway, how do i enable logging? I have tried --level=debug but the transactions are not being output at all

rienafairefr commented 8 years ago

Thanks for doing the testing. pull the new source from the repo, then restart the setup, that should work now.

config key value pairs are specified --key value, not --key=value, so debug would be --level debug but it's not really verbose for now. I'll add more

scottrobertson commented 8 years ago

Thanks.

I am getting no output at all

scottrobertson commented 8 years ago
python pynYNAB/scripts/csvimport.py ~/Downloads/ynab.csv example --level debug --email *** --password *** --budgetname "My Budget"
rienafairefr commented 8 years ago

can you get new source, commit a6bf0812e6a5d1b07c684bb8ceeb2a46760575ba and see if you still get nothing ? This works for me:

D:\Documents\nYNABapi>C:\Python27\python.exe pynYNAB\scripts\csvimport.py tests\data\test.csv example --level debug
pynYNAB CSV import
DEBUG:pynYNAB:selected schema example
DEBUG:pynYNAB:schema headers [u'date', u'payee', u'amount', u'memo', u'account']

DEBUG:pynYNAB:OK starting the import from D:\Documents\nYNABapi\tests\data\test.csv
DEBUG:pynYNAB:read line 2016-02-01,Super Pants Inc.,-20,Buying pants,Cash

DEBUG:pynYNAB:searching for account Cash
ERROR:pynYNAB:Couldnt find this account: Cash

In this case, email,password,budgetname are setup in ynab.conf

scottrobertson commented 8 years ago

That worked :) it now cannot find the Account though

scottrobertson commented 8 years ago

Think i may know why

scottrobertson commented 8 years ago

woohoo, that worked. I had a space at the start of the account name.

Duplicate checking does not seem to be working.

rienafairefr commented 8 years ago

have you tested with the latest code? Seems to be working now