Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 544bd11

Browse files
authored
Ignore missing files when used with Remarkable 2 (#14)
* Ignore missing thumbnails during dump * Ignore missing metadata file during load
1 parent b5f0367 commit 544bd11

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rmapy/document.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,12 @@ def dump(self, file: BytesOrString) -> None:
261261
zf.writestr(f"{self.ID}/{page.order}-metadata.json",
262262
json.dumps(page.metadata))
263263
page.page.seek(0)
264-
zf.writestr(f"{self.ID}.thumbnails/{page.order}.jpg",
265-
page.thumbnail.read())
264+
try:
265+
zf.writestr(f"{self.ID}.thumbnails/{page.order}.jpg",
266+
page.thumbnail.read())
267+
except AttributeError:
268+
log.debug(f"missing thumbnail during dump: {self.ID}: {page.order}")
269+
pass
266270
if isinstance(file, BytesIO):
267271
file.seek(0)
268272

@@ -321,9 +325,14 @@ def load(self, file: BytesOrString) -> None:
321325
with zf.open(p, 'r') as rm:
322326
page = BytesIO(rm.read())
323327
page.seek(0)
324-
with zf.open(p.replace(".rm", "-metadata.json"), 'r') as md:
325-
metadata = json.load(md)
326328

329+
p_meta = p.replace(".rm", "-metadata.json")
330+
try:
331+
with zf.open(p_meta, 'r') as md:
332+
metadata = json.load(md)
333+
except KeyError:
334+
log.debug(f"missing metadata: {p_meta}")
335+
metadata = None
327336
thumbnail_name = p.replace(".rm", ".jpg")
328337
thumbnail_name = thumbnail_name.replace("/", ".thumbnails/")
329338
try:

0 commit comments

Comments
 (0)