Closed bdarcus closed 13 years ago
At the moment, a basic hello world:
import pyzotero.zotero as z
zot = z.Zotero(user id, user key)
items = zot.items_data('top_level_items')
for i in items:
print i['title']
This would return the first 50 top-level library items (the API will only retrieve 50 at a time), and print their titles.
I'm not currently abstracting the returned data into new objects (such as Items, Collections, Groups), just returning lists containing dicts, mainly because I haven't gotten as far as thinking about what people might want to do with them once they've been retrieved. Admittedly, this is a bit minimal. I'll have a think about how best to deal with this. One problem that leaps out is how to create properties for a notional Item
object when properties vary from item to item; they always have titles and IDs, but not always abstracts, publishers etc. I suppose I could just add them as properties on the fly, and handle missing properties gracefully with a custom error. I could also give methods like items_data
more intuitive names. Let me know what you think.
The latest commit on the dev branch:
SHA: 937cbf42208638eaa4e7a52cd1781dc0ed955ab7
creates Item objects for any calls to items_data
. So you can do:
import pyzotero.zotero as z
zot = z.Zotero(user id, user key)
items = zot.items_data('top_level_items')
for item in items:
print 'Author: %s\nTitle: %s\nID: %s' % (item.author, item.title, item.id)
You'll just get None
for any attribute that doesn't exist. I'm not 100% sure this is the way to go (since creating instance attributes on the fly is Bad), but still.
Not sure if this is helpful in terms of ideas, but I came across a twitter client library a bit ago which sounded interesting:
http://mike.verdone.ca/twitter/
In particular, the statement "Its methods are directly bound to the Twitter API's URLs."
Hmm. I could do that, it's only about 25 methods.
SHA: 9c34318376a94d9274fccad83720841c161e0fad (https://github.com/urschrei/pyzotero/tree/dev)
I like this a lot better, even though it's going to entail a lot more work to implement every possible API call.
I tried this again, using the example in the updated README, and got this error:
$ python zot.py
Traceback (most recent call last):
File "zot.py", line 4, in <module>
items = zot.items()
File "/usr/local/lib/python2.6/dist-packages/pyzotero/zotero.py", line 109, in wrapped_f
return eval(output_func)(retr)
File "/usr/local/lib/python2.6/dist-packages/pyzotero/zotero.py", line 353, in items_data
return self.standard_items(retrieved)
File "/usr/local/lib/python2.6/dist-packages/pyzotero/zotero.py", line 367, in standard_items
[e.text.lower() for e in elem.iter('th')])
AttributeError: _ElementInterface instance has no attribute 'iter'
I suspect you have an older version of elementtree installed. Can you try pip install elementtree --upgrade
, then re-running your script and/or tests.py
I ended up upgrading the default ubuntu 2.6 to 2.7; that solved it.
So it might just be me, and the end of a long day, but I'm struggling a bit with the API.
Can you perhaps include a hello world that just lists entries in a library and prints out the titles?
More specifically, I guess I'm looking for really straightforward methods like:
library.items
- list of item dictionaries, maybe with optional filter parameterlibrary.item
- item by idlibrary.collections
- list of collectionsSo that I can just do:
Or: