-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
code changes via PM from u/fio_smiles #26
Conversation
"I don't know if that will work with Python 3+" Let's review and test it, see if we can build on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'd consider here is doing a Python version check before each of the relevant steps and doing what needs to be done only then. Wasn't there another error you were getting? Also need to check before importing config parser which version to import.
PM him back and get him to join Github so we can credit him properly! |
Or her! Accidental sexism, sorry! |
I'm working on it via PM :-) S/he is already intrigued by GitHub and might sign up. Would be cool! |
Okay I'm having trouble running this modified code. As-is I got this error:
So I tried installing
So I did:
I don't know what Without a better understanding of Python, I'm going to have to pass on this code change. Sorry. |
I'll see if I can work it out over the weekend.
…On 20 Oct 2017 22:16, "Torben Gundtofte-Bruun" ***@***.***> wrote:
Okay I'm having trouble running this modified code. As-is I got this error:
Traceback (most recent call last):
File "newtest.py", line 27, in <module>
from future import unicode_literals # issue #25
ImportError: No module named future
So I tried installing future with the usual command sudo python -m pip
install future but then it said:
Could not import setuptools which is required to install from a source distribution.
Please install setuptools.
So I did: sudo python -m pip install setuptools followed by sudo python
-m pip install future. Then I got:
Traceback (most recent call last):
File "newtest.py", line 27, in <module>
from future import unicode_literals # issue #25
ImportError: cannot import name unicode_literals
I don't know what unicode_literals is but I tried installing that like
above, but failed ("No matching distribution found for unicode_literals").
Without a better understanding of Python, I'm going to have to pass on
this code change. Sorry.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APeoH4RQXdJEVxcHeVjDp5v7uXlY96oRks5suQ2jgaJpZM4QAeNq>
.
|
She :) It's future which may have been lost in formatting, see this link: |
Ahhh, sorry the automatically formating is ruining it, there's two underscores before and after the word future, if you follow the link it should make more sense. |
Welcome @fiosmiles!! Great to see you on board! I've added the underscores (see new commit linked above) and now there's just a single issue left, but I can't figure out how to solve it:
I've tried appending
That's when I force the script to run as Python 2 (using the linux command |
I haven't played with this yet. That future thing is interesting! Edit: I see what you meant about auto formatting now @fiosmiles! Does the CSV without the newline output correctly on python 3? The reason I had it was because I was getting extra blank rows between each row without. |
Yes it does. I think the |
I think I ran into trouble with that on Windows. Will report back later.
…On 21 Oct 2017 13:00, "Torben Gundtofte-Bruun" ***@***.***> wrote:
Does the CSV without the newline output correctly on python 3?
Yes it does. I think the "wb" setting in line 125 did the trick.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APeoH19bCVVq6p0jMAoIahIQ6gF3fA4Fks5sudzugaJpZM4QAeNq>
.
|
I'm getting errors. And for encoding the delimiter: |
@nocalla is there a sample file that everyone is using? If so, can you point me at it and I'll try that file, or if not can you share your file or some version of it and I'll try it on my end. |
Also, this is something I was looking at when I hacked this to work for me on 2.7, maybe the switch is worth implementing if it's just not compatible with 3+ https://www.reddit.com/r/ynab/comments/77d7rt/tools_bank2ynab_heres_a_script_that_helps_with/ |
There isn't a test file. We should definitely make one. That has umlauts
and ends with a newline! I'll have a read of the link and see what I can
make of it if I can work out what's going wrong on my end.
…On 21 Oct 2017 23:32, "fiosmiles" ***@***.***> wrote:
Wrong link, correction: https://stackoverflow.com/
questions/29840849/writing-a-csv-file-in-python-that-works-
for-both-python-2-7-and-python-3-3-in
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APeoH6EGNoViQpBoeIomEG0Tu9MTkLLbks5sunEEgaJpZM4QAeNq>
.
|
Here's a test file, feel free to add more in that folder: https://github.com/torbengb/bank2ynab/tree/master/test-data |
I like this solution for the CSV issue. |
Also, we have to account for the renamed configparser! I think both of you have installed the Python 3 version as a workaround, but we should make it dependent on the pre-installed modules only. I think the best way to do that is import ConfigParser as configparser near the top of the code! |
Also remove delimiter encoding as shouldn't be needed with unicode_literals and was causing me errors Also move future to top of file to prevent error SyntaxError: from __future__ imports must occur at the beginning of the file TypeError: "delimiter" must be string, not bytes
Add python version check for csv writing
If running 2.x, import ConfigParser but rename it to configparser. I don't think this should cause any issues with the features we're using of the config parser.
Add support for 2.x version of configparser
This all works fine at my end, but I need @fiosmiles and @torbengb to test it out, because I know it won't work properly at your end! If we can pinpoint the errors, then we can track down what to focus on, so please paste your lovely exceptions. |
I like double quotes
I'll test your code on my Linux (tonight?) and reply then. |
Sorry to bring bad news, but it doesn't run against my normal CSV file (very similar to the uploaded test file). With Python 2 I get this error:
And with Python 3 I get this error:
I then tried a search&replace for all the German umlaut characters in both lowercase&uppercase, but I still got the errors. I noted that the VISA CSV export has a I then used Notepad++ to convert the CSV file to ANSI file format. Note that I only converted the bank CSV and not the VISA CSV. After that, the error in Python 2 remains but the script ran successfully in Python 3! I can't make much out of this but I'm sure a detailed feedback might help you identify something I've missed. Mail me at torben@g-b.dk and I can email you the actual files back. I don't want to post them here. Greetings from rainy Austria, |
@nocalla I will test on my home Linux home tonight and respond here. |
Test result with Python3: success! No errors found. Test result with Python2:
|
I wonder is that encoding parameter actually required now.
…On 24 Oct 2017 16:43, "Torben Gundtofte-Bruun" ***@***.***> wrote:
Test result with Python3: *success!* No errors found.
Test result with Python2:
Traceback (most recent call last):
File "bank2ynab.py", line 197, in <module>
main()
File "bank2ynab.py", line 170, in main
all_configs = get_configs()
File "bank2ynab.py", line 34, in get_configs
config.read(conf_files, encoding = "utf-8")
TypeError: read() got an unexpected keyword argument 'encoding'
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APeoH-e-tazZHRmSX8dsOr7PGROosp1gks5svgWMgaJpZM4QAeNq>
.
|
Well, if I leave out the
But it still works in Python3! |
The python 2 version might be different to 3. May need to compare how they
handle things.
…On 24 Oct 2017 17:10, "Torben Gundtofte-Bruun" ***@***.***> wrote:
Well, if I leave out the , encoding = "utf-8" from line 34 then I get a
different error:
Traceback (most recent call last):
File "bank2ynab.py", line 196, in <module>
main()
File "bank2ynab.py", line 177, in main
g_config = fix_conf_params(all_configs[section])
AttributeError: ConfigParser instance has no attribute '__getitem__'
But it still works in Python3!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#26 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/APeoHyi5Yq9KqpFVHJzb-TnV-peWn27lks5svgwEgaJpZM4QAeNq>
.
|
Hang on, I downloaded new CSV files and also downloaded a fresh copy of the bank2ynab.py in this pull request. Test result with Python3: success! No errors found. Test result with Python2:
Then I removed the
Does this help you? |
Need to do some reading about ConfigParser! But thanks. |
Rebase to master
I handled this exact error in the py2 branch, the ConfigParser interface is different in 2 and 3, so that's done.
Eh, this is bitchy. Basically the encoding for these files is incompatible with utf-8 somewhere in its space. This is unsolvable with precision unless we include something like A possible strategy would be to do dummy
This has obvious performance implications, but it might be acceptable in most cases - considering people will use this once a month or so, waiting a few seconds more should not be a biggie. |
I like your idea of iterating through several charsets, it's actually an elegant solution. I hope it's worth the trouble! As for performance I'm sure it doesn't matter at all, given how the script already runs in the blink of an eye. I'd be surprised if it takes two seconds to complete this loop. |
I quite like the try except way also. Interesting approach. I still feel it's a bit weird that I'm not getting that error on Windows though. |
Merged into the py2 branch. #54 |
# source: survey response #26
code changes via PM from u/fio_smiles to address issue #25: "I don't know if that will work with Python 3+". Let's review and test it, see if we can build on it.
I will test it on my Linux tonight.