From 1a3ec4ff3249c383a03b7c10c2859b7fc51dcc27 Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Mon, 23 Aug 2021 13:43:12 +0200 Subject: [PATCH] compression --- fftcg/book.py | 5 +++-- fftcg/carddb.py | 3 ++- fftcg/utils.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fftcg/book.py b/fftcg/book.py index 6a8797e..ca52efa 100644 --- a/fftcg/book.py +++ b/fftcg/book.py @@ -1,4 +1,5 @@ import logging +import bz2 import pickle from PIL import Image @@ -64,7 +65,7 @@ class Book: book: dict[str, Cards] try: - with open(BOOK_PICKLE_NAME, "rb") as file: + with bz2.BZ2File(BOOK_PICKLE_NAME, "r") as file: book = pickle.load(file) except FileNotFoundError: book = {} @@ -79,5 +80,5 @@ class Book: book[page["file_name"]] = page["cards"] # update book.yml file - with open(BOOK_PICKLE_NAME, "wb") as file: + with bz2.BZ2File(BOOK_PICKLE_NAME, "w") as file: pickle.dump(book, file) diff --git a/fftcg/carddb.py b/fftcg/carddb.py index 6d2f0a3..cd66468 100644 --- a/fftcg/carddb.py +++ b/fftcg/carddb.py @@ -1,5 +1,6 @@ from __future__ import annotations +import bz2 import pickle from fftcg import Card @@ -27,7 +28,7 @@ class CardDB: # load book.yml file book: dict try: - with open(BOOK_PICKLE_NAME, "rb") as file: + with bz2.BZ2File(BOOK_PICKLE_NAME, "r") as file: book = pickle.load(file) except FileNotFoundError: book = {} diff --git a/fftcg/utils.py b/fftcg/utils.py index 5076087..e53e670 100644 --- a/fftcg/utils.py +++ b/fftcg/utils.py @@ -3,7 +3,7 @@ from .grid import Grid # constants GRID = Grid((10, 7)) # default in TTsim: 10 columns, 7 rows RESOLUTION = Grid((429, 600)) # default in TTsim: 480x670 pixels per card -BOOK_PICKLE_NAME = "book.pickle" +BOOK_PICKLE_NAME = "book.pickle.bz2" # card back URL (image by Aurik) CARD_BACK_URL = "http://cloud-3.steamusercontent.com/ugc/948455238665576576/85063172B8C340602E8D6C783A457122F53F7843/"