Skip to content

Commit

Permalink
Distinguish between HTML snapshots and attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Jan 30, 2018
1 parent a787673 commit 6f2a78a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions pyzotero/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,20 @@ 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
elif fmt != 'json':
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


Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6f2a78a

Please sign in to comment.