simplify if statements by using walrus operators (#7671)

This commit is contained in:
Mike Fährmann
2025-07-22 18:34:38 +02:00
parent e8b2a496ba
commit a097a373a9
83 changed files with 239 additions and 466 deletions

View File

@@ -89,8 +89,7 @@ class PixivExtractor(Extractor):
if tag["is_registered"]]
if self.meta_captions and not work.get("caption") and \
not work.get("_mypixiv") and not work.get("_ajax"):
body = self._request_ajax("/illust/" + str(work["id"]))
if body:
if body := self._request_ajax("/illust/" + str(work["id"])):
work["caption"] = self._sanitize_ajax_caption(
body["illustComment"])
@@ -293,8 +292,7 @@ class PixivExtractor(Extractor):
def _extract_ajax_url(self, body):
try:
original = body["urls"]["original"]
if original:
if original := body["urls"]["original"]:
return original
except Exception:
pass
@@ -699,8 +697,7 @@ class PixivRankingExtractor(PixivExtractor):
except KeyError:
raise exception.AbortExtraction(f"Invalid mode '{mode}'")
date = query.get("date")
if date:
if date := query.get("date"):
if len(date) == 8 and date.isdecimal():
date = f"{date[0:4]}-{date[4:6]}-{date[6:8]}"
else: