Xunius / Menotexport

Python solution to export annotations from your Mendeley library.
GNU General Public License v3.0
124 stars 20 forks source link

Multiple Tags in One Document causes Error #14

Open StRuoff opened 7 years ago

StRuoff commented 7 years ago

When having multiple Tags in a Document in Mendeley, the following error shows up if you want to write a "ris" file:

Traceback (most recent call last): File "menotexport.py", line 1445, in <module> args.separate,args.zotero,args.verbose) File "menotexport.py", line 1292, in main fidii,fnameii,allfolders,action,separate,iszotero,verbose) File "menotexport.py", line 1057, in processFolder tagsdict=extracttags.groupByTags(annotations) File "/home/ruof_st/.Software/anaconda2/lib/python2.7/site-packages/lib/extracttags.py", line 38, in groupByTags tagsii=['@'+kk for kk in tagsii] TypeError: cannot concatenate 'str' and 'list' objects Also, if this error is not showing up (by convering the list to a string in extracttags.py), the script stops at:

# <Menotexport>: Exporting meta-data and annotations to .ris file... Traceback (most recent call last): File "menotexport.py", line 1444, in <module> args.separate,args.zotero,args.verbose) File "menotexport.py", line 1291, in main fidii,fnameii,allfolders,action,separate,iszotero,verbose) File "menotexport.py", line 1098, in processFolder risfolder,allfolders,isfile,iszotero,verbose) File "/home/ruof_st/.Software/anaconda2/lib/python2.7/site-packages/lib/export2ris.py", line 263, in exportAnno2Ris allfolders,isfile,iszotero,verbose) File "/home/ruof_st/.Software/anaconda2/lib/python2.7/site-packages/lib/export2ris.py", line 287, in exportDoc2Ris risdata=parseMeta(docii,basedir,isfile,iszotero) File "/home/ruof_st/.Software/anaconda2/lib/python2.7/site-packages/lib/export2ris.py", line 200, in parseMeta keywords=list(set(keywords)) TypeError: unhashable type: 'list'

If I print, how the tags look like in the python code it gives this: [[u'LES', u'detailed chemistry', u'diagnostics', u'swirl burner'], u'LES'] If I am right, the tags are loaded in a List, and afterwards the folder name is added to the list, making it a list of lists, causing the problem.

Xunius commented 7 years ago

Hi StRuoff Thanks for reporting. Do you get any error exporting to "bib" files? I'll have a closer look in the weekend.

StRuoff commented 7 years ago

Yes, I get it for bib too. I think the error is caused by else: tags=[meta['tags'],folder] in Line 390 of menotexport.py. That is in the section getting the highlighting in the PDFs (function getHighlights). A similar line is found in the getNotes and getDocNotes, but the elif condition before that else is a bit different. Maybe that's causing the problem.

What I forgot to mention: I am using Python 2.7.13 with an anaconda2 installation on a SLED12 mashine. Maybe that error doesn't appear in Python3.

StRuoff commented 7 years ago

The condition I mentioned is: elif type(meta['tags']) is list and folder not in meta['tags']: The Problem for me is, that one of the Tags in the Document is the same as the folder name, making the condition false and jumping to the above mentiond else statement. Is this the intended behaviour, and if yes, why is this condition different to the other two functions I metnioned above?

Xunius commented 7 years ago

Hi StRuooff, I just got time to look into this. You mentioned at Line 390 of menotexport.py the line is:

else: tags=[meta['tags'],folder]

But in the most recent (it's actually quite some time ago) line 390 is:

elif type(meta['tags']) is list and folder in meta['tags']:

which is the condition for folder name being the same as one the tags in in the tag list. So I wonder could you be using an older version and I've patched this problem up already?

Btw the treatment for that condition is

tags=meta['tags']

So it doens't add the folder to the tag list again.

Xunius commented 7 years ago

I got it. You mentened that you installed via anaconda. I just checked it and indeed the anaconda version is wrong. I've fixed that. Pls try upgrade it:

conda install -c guangzhi menotexport

which will upgrade to 1.4.3. Give it a try and let me know if you encounter any further error. Sorry for the trouble.

StRuoff commented 7 years ago

Thanks for the response! I figured it out myself, how to patch it, an ended up with exactly the line you suggested to add. Are there other enhancements in the new version?

Xunius commented 7 years ago

Good! I don't think there's anything new. If you have any idea in mind just let me know.

StRuoff commented 7 years ago

can I post my questions in this issue or create a new one? I'm quite new to GitHub, so I don't want to mess with the "structures" of it :-)

Xunius commented 7 years ago

I'm no pro user either. I guess open a new one, to make it easier for other people to search.