diff --git a/doc/index.rst b/doc/index.rst index 6e047c6..d539461 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -315,9 +315,9 @@ Retrieving Files A convenient wrapper around :py:meth:`Zotero.file()`. Writes an attachment to disk using the optional path and filename. If neither are supplied, the file is written to the current working directory, and a :py:meth:`Zotero.item()` call is first made to determine the attachment - filename. No error checking is done regarding the path. + filename. No error checking is done regarding the path. If successful, the full path including the file name is returned. - .. note:: HTML snapshots will be dumped as zip files, with "zip" appended to the file name. + .. note:: HTML snapshots will be dumped as zip files. These will be named with their API item key, and a .zip extension. .. code-block:: python diff --git a/pyzotero/zotero.py b/pyzotero/zotero.py index 9083c3a..f6a7a69 100644 --- a/pyzotero/zotero.py +++ b/pyzotero/zotero.py @@ -645,17 +645,18 @@ 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 = "{i}.zip".format(i=itemkey) if path: pth = os.path.join(path, filename) else: pth = filename - file = self.file(itemkey) - if self.snapshot: - self.snapshot = False - pth = pth + ".zip" - with open(pth, "wb") as f: - f.write(file) + to_write = self.file(itemkey) + with open(pth, 'wb') as f: + f.write(to_write) + return pth @retrieve def children(self, item, **kwargs):