urschrei / pyzotero

Pyzotero: a Python client for the Zotero API
https://pyzotero.readthedocs.org
Other
908 stars 99 forks source link

Feature Request - Add tags and modify comments of annotations #154

Closed Mjvolk3 closed 1 year ago

Mjvolk3 commented 2 years ago

Currently the Zotero.add_tags() only works for metadata tags, but it would be convenient to modify tags and even update comments of annotations. It wouldn't make much sense to modify the other items of the annotation dict, maybe annotation color. My use case is to connect Zotero notes to Dendron a note taking tool in VsCode. After importing notes to Dendron, I would like to be able to modify them there, and write the changes back to Zotero. This would be possible with the requested feature. Thanks for your consideration.

urschrei commented 2 years ago

This isn't currently supported by the Zotero API. See https://github.com/urschrei/pyzotero/issues/148

Mjvolk3 commented 2 years ago

Thanks for your speedy response! From what I saw it looks like the issue is that they haven't documented it yet.

urschrei commented 2 years ago

Hmm. I'll have to think about what the API looks like, and I'm hesitant to add public API methods for undocumented features.

In the mean time, v1.5.3 (just released to pypi) now supports annotation fields, so you can modify annotation items (retrieved as per #148), by altering their ['data']['annotationComment'] and ['data']['tags'] keys, then write the changes to your library using update_item(modified_item). I just tried this and the changes appear exactly as you would expect.

Mjvolk3 commented 2 years ago

Ok I have upgraded to v1.5.3.

all_annotations = zot.everything(zot.items(itemType="annotation"))
print(all_annotations[0])
zot.add_tags(all_annotations[0], "test-tag")
# Error
> InvalidItemFields: Invalid keys present in item 1: annotationText

Strangely the tag is added before the template check.

print(all_annotations[0]['data']['tags'])
> [{'tag': 'test-tag'}]

Since it is updated I try the following, and of course get the same error.

zot.update_item(all_annotations[0])
# Error
> InvalidItemFields: Invalid keys present in item 1: annotationText

I check the template on zotero.py and the annotationText is not a supported field. The following annotations fields are supported.

# annotation fields
"annotationColor",
"annotationType",
"annotationPageLabel",
"annotationPosition",
"annotationSortIndex",
"annotationComment",

Seems strange that "annotationText" isn't here. How were you able to get things to work?

urschrei commented 2 years ago

🤦‍♂️ I left out annotationText. I've just pushed 1.5.4 to pypi – try that? (sorry!)

Mjvolk3 commented 2 years ago

Works perfectly now. Thank you!

EricThrift commented 2 years ago

annotationAuthorName is also missing from the list of known keys in zotero.py, around line 1140. This prevents pyzotero from updating PDF annotations when sending back a modified version of the json returned by the API.

urschrei commented 2 years ago

@EricThrift Oops. Just published 1.5.5 with a fix.