From 0ab9772b3379d7e8838f39f7b78b5d2017d1c75d Mon Sep 17 00:00:00 2001
From: Markus Nyman <markus@nyman.dev>
Date: Thu, 12 Jan 2023 14:37:27 +0200
Subject: [PATCH] Prompt config if it doesn't exist

---
 TimeToTrakt.py | 43 +++++++++++++++++++++++--------------------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/TimeToTrakt.py b/TimeToTrakt.py
index b61d465..2a84304 100644
--- a/TimeToTrakt.py
+++ b/TimeToTrakt.py
@@ -58,15 +58,24 @@ def isAuthenticated():
 
 
 def getConfiguration() -> Config:
-    with open("config.json") as f:
-        data = json.load(f)
+    try:
+        with open("config.json") as f:
+            data = json.load(f)
 
-    return Config(
-        data["TRAKT_USERNAME"],
-        data["CLIENT_ID"],
-        data["CLIENT_SECRET"],
-        data["GDPR_WORKSPACE_PATH"],
-    )
+        return Config(
+            data["TRAKT_USERNAME"],
+            data["CLIENT_ID"],
+            data["CLIENT_SECRET"],
+            data["GDPR_WORKSPACE_PATH"],
+        )
+    except FileNotFoundError:
+        logging.info("config.json not found prompting user for input")
+        return Config(
+            input("Enter your Trakt.tv username: "),
+            input("Enter you Client id: "),
+            input("Enter your Client secret: "),
+            input("Enter your GDPR workspace path: ")
+        )
 
 
 config = getConfiguration()
@@ -817,18 +826,12 @@ def start():
 
 
 if __name__ == "__main__":
-    # Check that the user has created the config file
-    if os.path.exists("config.json"):
-        # Check that the user has provided the GDPR path
-        if os.path.isdir(config.gdpr_workspace_path):
-            start()
-        else:
-            logging.error(
-                "Oops! The TV Time GDPR folder '"
-                + config.gdpr_workspace_path
-                + "' does not exist on the local system. Please check it, and try again."
-            )
+    # Check that the user has provided the GDPR path
+    if os.path.isdir(config.gdpr_workspace_path):
+        start()
     else:
         logging.error(
-            "The 'config.json' file cannot be found - have you created it yet?"
+            "Oops! The TV Time GDPR folder '"
+            + config.gdpr_workspace_path
+            + "' does not exist on the local system. Please check it, and try again."
         )