From 6f2a78a02282e5c97f1f23eb48bc83d09a3de69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Wed, 17 May 2017 20:54:50 +0100 Subject: [PATCH] Distinguish between HTML snapshots and attachments --- pyzotero/zotero.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/pyzotero/zotero.py b/pyzotero/zotero.py index 5e63691..0f68426 100644 --- a/pyzotero/zotero.py +++ b/pyzotero/zotero.py @@ -179,9 +179,6 @@ def wrapped_f(self, *args, **kwargs): processor = self.processors.get(content) # process the content correctly with a custom rule return processor(parsed) - if fmt == "snapshot": - # we need to dump as a zip! - self.snapshot = True if fmt == 'bibtex': return bibtexparser.loads(retrieved.text) # it's binary, so return raw content @@ -189,7 +186,13 @@ def wrapped_f(self, *args, **kwargs): return retrieved.content # no need to do anything special, return JSON else: - return retrieved.json() + # is this a snapshot though? + retr = retrieved.json() + # I know, I know + if isinstance(retr, dict) and retr['data']['linkMode'] == u"imported_url": + return retrieved.content + else: + return retr return wrapped_f @@ -589,17 +592,17 @@ def dump(self, itemkey, filename=None, path=None): Dump a file attachment to disk, with optional filename and path """ if not filename: - filename = self.item(itemkey)['data']['filename'] + try: + filename = self.item(itemkey)['data']['filename'] + except TypeError: + filename = "item.html.zip" if path: pth = os.path.join(path, filename) else: pth = filename - file = self.file(itemkey) - if self.snapshot: - self.snapshot = False - pth = pth + ".zip" + to_write = self.file(itemkey) with open(pth, 'wb') as f: - f.write(file) + f.write(to_write) @retrieve def children(self, item, **kwargs):