From ceb8cb4a03bd38721b221e09d63563ad30cab312 Mon Sep 17 00:00:00 2001 From: Hans5958 Date: Thu, 7 Apr 2022 22:18:07 +0700 Subject: [PATCH] Improve CSTW and whoops --- tools/formatter.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tools/formatter.py b/tools/formatter.py index 6c1e3a37..b5fc6fee 100644 --- a/tools/formatter.py +++ b/tools/formatter.py @@ -114,26 +114,29 @@ def fix_no_protocol_urls(entry: dict): return entry def convert_website_to_subreddit(entry: dict): - if (not "website" in entry or not entry['website']) or ("subreddit" in entry and not entry['subreddit'] == ""): + if not "website" in entry or not entry['website']: return entry if re.match(CWTS_REGEX, entry["website"]): new_subreddit = re.sub(CWTS_REGEX, SUBREDDIT_TEMPLATE, entry["website"]) if (new_subreddit.lower() == entry["subreddit"].lower()): entry["website"] = "" - else: + elif "subreddit" in entry and entry['subreddit'] == "": entry["subreddit"] = new_subreddit entry["website"] = "" return entry def convert_subreddit_to_website(entry: dict): - if (not "subreddit" in entry or not entry['subreddit']) or ("website" in entry and not entry['website'] == ""): + if not "subreddit" in entry or not entry['subreddit']: return entry if re.match(CSTW_REGEX, entry["subreddit"]): - entry["website"] = entry["subreddit"] - entry["subreddit"] = "" + if (entry["website"].lower() == entry["subreddit"].lower()): + entry["subreddit"] = "" + elif "website" in entry and entry['website'] == "": + entry["website"] = entry["subreddit"] + entry["subreddit"] = "" return entry