chore: skip unnecessary key checks prior to accessing a dictionary (#4497)

This commit is contained in:
Bowen Liang
2024-05-19 18:30:45 +08:00
committed by GitHub
parent aa13d14019
commit 04ad46dd31
30 changed files with 45 additions and 44 deletions

View File

@@ -132,17 +132,17 @@ def extract_using_readabilipy(html):
}
# Populate article fields from readability fields where present
if input_json:
if "title" in input_json and input_json["title"]:
if input_json.get("title"):
article_json["title"] = input_json["title"]
if "byline" in input_json and input_json["byline"]:
if input_json.get("byline"):
article_json["byline"] = input_json["byline"]
if "date" in input_json and input_json["date"]:
if input_json.get("date"):
article_json["date"] = input_json["date"]
if "content" in input_json and input_json["content"]:
if input_json.get("content"):
article_json["content"] = input_json["content"]
article_json["plain_content"] = plain_content(article_json["content"], False, False)
article_json["plain_text"] = extract_text_blocks_as_plain_text(article_json["plain_content"])
if "textContent" in input_json and input_json["textContent"]:
if input_json.get("textContent"):
article_json["plain_text"] = input_json["textContent"]
article_json["plain_text"] = re.sub(r'\n\s*\n', '\n', article_json["plain_text"])