From f940a23e7e5acd1ace7099cae4d3f8f81c0ad080 Mon Sep 17 00:00:00 2001 From: inexcode Date: Mon, 15 Aug 2022 22:51:01 +0400 Subject: [PATCH] Make sure jobs file exists on read --- selfprivacy_api/utils/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/selfprivacy_api/utils/__init__.py b/selfprivacy_api/utils/__init__.py index f34fdad..1904f76 100644 --- a/selfprivacy_api/utils/__init__.py +++ b/selfprivacy_api/utils/__init__.py @@ -69,6 +69,10 @@ class ReadUserData(object): elif file_type == UserDataFiles.TOKENS: self.userdata_file = open(TOKENS_FILE, "r", encoding="utf-8") elif file_type == UserDataFiles.JOBS: + # Make sure file exists + if not os.path.isfile(JOBS_FILE): + with open(JOBS_FILE, "w", encoding="utf-8") as jobs_file: + jobs_file.write("[]") self.userdata_file = open(JOBS_FILE, "r", encoding="utf-8") else: raise ValueError("Unknown file type")