From b037fcbbfcc0a33d255270ab6a39cfa2f0f1287b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Thu, 18 May 2017 22:04:47 +0100 Subject: [PATCH] Dump HTML snapshots with unique file names based on item key This change also alters dump() to return the path and file name, see discussion in #75 --- doc/index.rst | 4 ++-- pyzotero/zotero.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index 347e36b..f60e483 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -309,9 +309,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 d9a469c..e97cac3 100644 --- a/pyzotero/zotero.py +++ b/pyzotero/zotero.py @@ -595,7 +595,7 @@ def dump(self, itemkey, filename=None, path=None): try: filename = self.item(itemkey)['data']['filename'] except TypeError: - filename = "item.html.zip" + filename = "{i}.zip".format(i=itemkey) if path: pth = os.path.join(path, filename) else: @@ -603,6 +603,7 @@ def dump(self, itemkey, filename=None, path=None): to_write = self.file(itemkey) with open(pth, 'wb') as f: f.write(to_write) + return pth @retrieve def children(self, item, **kwargs):