Improve CSTW and whoops

This commit is contained in:
Hans5958 2022-04-07 22:18:07 +07:00
parent 90f9b05092
commit ceb8cb4a03

View file

@ -114,24 +114,27 @@ def fix_no_protocol_urls(entry: dict):
return entry return entry
def convert_website_to_subreddit(entry: dict): 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 return entry
if re.match(CWTS_REGEX, entry["website"]): if re.match(CWTS_REGEX, entry["website"]):
new_subreddit = re.sub(CWTS_REGEX, SUBREDDIT_TEMPLATE, entry["website"]) new_subreddit = re.sub(CWTS_REGEX, SUBREDDIT_TEMPLATE, entry["website"])
if (new_subreddit.lower() == entry["subreddit"].lower()): if (new_subreddit.lower() == entry["subreddit"].lower()):
entry["website"] = "" entry["website"] = ""
else: elif "subreddit" in entry and entry['subreddit'] == "":
entry["subreddit"] = new_subreddit entry["subreddit"] = new_subreddit
entry["website"] = "" entry["website"] = ""
return entry return entry
def convert_subreddit_to_website(entry: dict): 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 return entry
if re.match(CSTW_REGEX, entry["subreddit"]): if re.match(CSTW_REGEX, entry["subreddit"]):
if (entry["website"].lower() == entry["subreddit"].lower()):
entry["subreddit"] = ""
elif "website" in entry and entry['website'] == "":
entry["website"] = entry["subreddit"] entry["website"] = entry["subreddit"]
entry["subreddit"] = "" entry["subreddit"] = ""