From 82d1e4944c1fa0eb0036ff2756e451d4fb5eec7f Mon Sep 17 00:00:00 2001 From: Frisk Date: Mon, 16 Mar 2020 14:58:19 +0100 Subject: [PATCH] Added try catch for not having new wiki_url value in the settings --- rcgcdw.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/rcgcdw.py b/rcgcdw.py index 4f76da5..4f46ee7 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -120,7 +120,8 @@ def prepare_paths(): """Set the URL paths for article namespace and script namespace WIKI_API_PATH will be: WIKI_DOMAIN/api.php WIKI_ARTICLE_PATH will be: WIKI_DOMAIN/articlepath/$1 where $1 is the replaced string - WIKI_SCRIPT_PATH will be: WIKI_DOMAIN/""" + WIKI_SCRIPT_PATH will be: WIKI_DOMAIN/ + WIKI_JUST_DOMAIN will be: WIKI_DOMAIN""" def quick_try_url(url): """Quickly test if URL is the proper script path, False if it appears invalid @@ -133,9 +134,12 @@ def prepare_paths(): return False except (KeyError, requests.exceptions.ConnectionError): return False - - parsed_url = urlparse(settings["wiki_url"]) - for url_scheme in (settings["wiki_url"], settings["wiki_url"].split("wiki")[0]): + try: + parsed_url = urlparse(settings["wiki_url"]) + except KeyError: + logger.critical("wiki_url is not specified in the settings. Please provide the wiki url in the settings and start the script again.") + sys.exit(1) + for url_scheme in (settings["wiki_url"], settings["wiki_url"].split("wiki")[0], urlunparse((*parsed_url[0:2], "", "", "", ""))): # check different combinations, it's supposed to be idiot-proof tested = quick_try_url(url_scheme + "/api.php?action=query&format=json&meta=siteinfo") if tested: WIKI_API_PATH = urlunparse((*parsed_url[0:2], "", "", "", "")) + tested.json()["query"]["general"]["scriptpath"] + "/api.php"