From eac2e7a79aa678b2dd055f7684bf44cd8fde769e Mon Sep 17 00:00:00 2001 From: pictuga Date: Thu, 12 Dec 2013 16:41:58 +0100 Subject: [PATCH] Try to avoid erros with saving Mainly: do not create empty cache file, and accept empty cache file (doesn't sound logical but still) --- morss.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/morss.py b/morss.py index 4099a0e..f8cbc2b 100644 --- a/morss.py +++ b/morss.py @@ -140,7 +140,8 @@ class Cache: if os.path.isfile(self._file): data = open(self._file).read() - self._cached = json.loads(data) + if data: + self._cached = json.loads(data) if persistent: self._cache = self._cached @@ -170,8 +171,10 @@ class Cache: if not os.path.exists(self._dir): os.makedirs(self._dir) + out = json.dumps(self._cache, indent=4) + with open(self._file, 'w+') as file: - file.write(json.dumps(self._cache, indent=4)) + file.write(out) def isYoungerThan(self, sec): if not os.path.exists(self._file):