urschrei / pyzotero

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

get_subset does not return actual data #143

Closed nchachereau closed 3 years ago

nchachereau commented 3 years ago

The documentation states that get_subset should "Retrieve an arbitrary set of non-adjacent items" and return them as a "list of dicts".

Instead, get_subset returns a (1-dimensional) list of the keynames of the dicts, but not the actual data of the retrieved items. For instance, given a list keys containing three items:

>>> zot.get_subset(keys)
['key', 'version', 'library', 'links', 'meta', 'data', 'key', 'version', 'library', 'links', 'meta', 'data', 'key', 'version', 'library', 'links', 'meta', 'data']

I haven't looked deeply into the issue, but I might be able to propose a possible solution. The code of get_subset seems rather complicated. Instead of using get_subset, I ended up using simply the following:

for chunk in [keys[pos:pos+50] for pos in range(0, len(keys), 50)]:
    zot_items += zot.items(itemKey=",".join(chunk))

Maybe the second line might can be an acceptable implementation of get_subset, i.e. something like self.items(itemKey=",".join(subset)). Or even the whole snippet might be an inspiration, so that get_subset would not complain about subsets of more than 50 items, but would retrieve everything sequentially, which might make the function even more useful. But these are just ideas - feel free to solve the bug as you see fit.

By the way, thank you for this package. I needed to transfer some non standard data into my Zotero library, and having a Python interface to the API was very helpful!

(Not sure it is relevant, but here is the information in case: Platform: Ubuntu 18.04, Python version: 3.6.9, Pyzotero version: pyzotero-1.4.24)