From 5c45eb860210b8cd6378457e00d87affa4c3caf0 Mon Sep 17 00:00:00 2001 From: funkyhippo Date: Sun, 12 Dec 2021 11:43:36 -0800 Subject: [PATCH] Handle empty descriptions gracefully. #8 --- proxy/sources/mangadex.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/proxy/sources/mangadex.py b/proxy/sources/mangadex.py index 89992fb2..a855e2b0 100644 --- a/proxy/sources/mangadex.py +++ b/proxy/sources/mangadex.py @@ -1,7 +1,7 @@ from concurrent.futures.thread import ThreadPoolExecutor from datetime import datetime import html -from typing import Dict +from typing import Dict, Union from django.core.cache import cache from django.http import HttpResponse @@ -310,12 +310,19 @@ def md_api_common(self, meta_id): title = title_metadata[title_precedence] break + description_object: Union[list, Dict[str, str]] = main_data["data"][ + "attributes" + ]["description"] + description: str = ( + description_object.get(SUPPORTED_LANG, "No English description.") + if len(description_object) + else "No description." + ) + return { "slug": meta_id, "title": title, - "description": main_data["data"]["attributes"]["description"].get( - SUPPORTED_LANG, "No English description." - ), + "description": description, "author": "", "artist": "", "groups": groups_dict,