Maboroshy / Note-Station-to-markdown

The cross-platform script that converts notes from Synology Note Station to markdown files
Apache License 2.0
240 stars 51 forks source link

Error if attachments with identical file names #6

Closed andreas-vester closed 6 years ago

andreas-vester commented 6 years ago

The script delivers an error if two notes have attachments, which have identical filenames.

The error message reads as follows:

Traceback (most recent call last): File "nsx2md.py", line 119, in <module> '{}/{}/{}'.format(notebook_title, media_dir, name)) FileExistsError: [WinError 183] Eine Datei kann nicht erstellt werden, wenn sie bereits vorhanden ist:

Would it be possible to change the code in a way that it attaches increasing numbers to filenames if they already exist?

Maboroshy commented 6 years ago

It's possible. I'll look into it.

Maboroshy commented 6 years ago

I've uploaded a new version which should resolve the issue. Please, test it.

andreas-vester commented 6 years ago

This version extracted more notes from my notebook than before. It seems to handle identical file names correctly. I saw some PDF docs with numbers attached, such as text.pdf, text_1.pdf, text_1_2.pdf and so on. However, it didn't finish correctly. I get an error. So far, I didn't changed any options inside the script.

c:\tmp>python nsx2md.py Found pandoc 2.3.1 Converting notebook "Family" Traceback (most recent call last): File "nsx2md.py", line 98, in content = Path(pandoc_output_file.name).read_text() File "C:\Users\mail\AppData\Local\Programs\Python\Python37\lib\pathlib.py", line 1190, in read_text return f.read() File "C:\Users\mail\AppData\Local\Programs\Python\Python37\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 1440: character maps to

Maboroshy commented 6 years ago

I've uploaded fixed version. Seems to work correctly on my Win 7 test VM. Please, test.

andreas-vester commented 6 years ago

It may work, but I wasn't able to completely test it, yet. I encountered another "issue". Given the attachment contains some kind of special character, the script fails to finish. For example, I had notes with attachments conatining characters such as '*' and "" (quotation marks). I guess there are more special characters that will lead to failure.

Maybe it makes sense to check whether the attachment has a valid file name. If not, skip the attachment and print a list at the end with all failing files. One could then decide whether the note is important enough in order to change it in Note Station and start the export process again.

I will continue testing tomorrow.

Maboroshy commented 6 years ago

I've uploaded the version with extra path safety for all directories or files created by script. It won't skip anything but make paths safe by replacing characters Windows doesn't like.

andreas-vester commented 6 years ago

I think the script now converted all my notes, but I'm not 100% sure. The script didn't finish with the correct success message. This might be due to the fact that I had some notes that contains a comma (,) in the title. I will change the respective titles and start the export again. I will let you know if this solves the issue. However, don't expect an answer during the next 48 hours.

Here's the message the script finally printed.

Traceback (most recent call last): File "nsx2md.py", line 111, in note_title = note_data['title'] KeyError: 'title'

Edit: I changed the following settings in the script to TRUE. However, the result is exactly the same. convert_spaces_in_links = True # Replace spaces in links with '%20' force_windows_filename_limitations = True

Maboroshy commented 6 years ago

Comma should be no problem. Looks like some of your notes have no title attribute. I thought that this attribute is always present and haven't made a fallback. I've implemented one now and updated the script.

andreas-vester commented 6 years ago

Aah, well that's probably true. Maybe some notes are just completely empty, i.e. created by mistake and have never been deleted.

andreas-vester commented 6 years ago

I quickly checked your latest version. The export is now properly working. 👍

Converted 4 notebooks and 2489 out of 2489 notes. Press Enter to quit...

Maboroshy commented 6 years ago

Great! I don't use Note Station myself, and your notebooks are very good test suite for the script. I'll close this issue and move to QON import script.

andreas-vester commented 6 years ago

Getting the correct links/attachments is more pressing on my side compared to the QON script (if I may express a priority wish ;-) ). Also, before moving to QON, I would like to see if there is some kind of import solution possible for Joplin. I read something about a Joplin terminal. However, I haven't used it so far. Thanks for your good work!

Maboroshy commented 6 years ago

I'll see what I can do about Joplin after I'll fix the links. ;-)