From 95a1a71a660204b49c5ef4a73e59c933ad042d69 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Sat, 31 Oct 2020 22:28:24 +0100 Subject: [PATCH] Minor refactor of comic.py --- cps/comic.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cps/comic.py b/cps/comic.py index 1bb23622..c228454c 100644 --- a/cps/comic.py +++ b/cps/comic.py @@ -62,14 +62,12 @@ def _cover_processing(tmp_file_name, img, extension): im.save(tmp_bytesio, format='JPEG') img = tmp_bytesio.getvalue() - prefix = os.path.dirname(tmp_file_name) - if img: - tmp_cover_name = prefix + '/cover.jpg' - image = open(tmp_cover_name, 'wb') - image.write(img) - image.close() - else: - tmp_cover_name = None + if not img: + return None + + tmp_cover_name = os.path.join(os.path.dirname(tmp_file_name), 'cover.jpg') + with open(tmp_cover_name, 'wb') as f: + f.write(img) return tmp_cover_name