aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-07-28 21:44:06 -0700
committerFuwn <[email protected]>2023-07-28 21:44:06 -0700
commit3536a5f9148cc477fd635a5adcc06041ea16f6bb (patch)
treee01354c4b86f0d7ffe1952cfebffd13e95047131
parentrefactor(due): like-functions to modules (diff)
downloadold.due.moe-3536a5f9148cc477fd635a5adcc06041ea16f6bb.tar.xz
old.due.moe-3536a5f9148cc477fd635a5adcc06041ea16f6bb.zip
refactor(manga): move rerequests to function
-rw-r--r--src/due/html/manga.py52
1 files changed, 29 insertions, 23 deletions
diff --git a/src/due/html/manga.py b/src/due/html/manga.py
index 8e74a63..dcf6aad 100644
--- a/src/due/html/manga.py
+++ b/src/due/html/manga.py
@@ -6,6 +6,34 @@ import os
from .utilities import seen
+def rerequest(manga, year):
+ mangadex_data = requests.get(
+ "https://api.mangadex.org/manga",
+ params={"title": manga["title"]["native"], "year": year},
+ ).json()["data"]
+
+ # This is very stupid. It should never get this far, anyway.
+ if len(mangadex_data) == 0:
+ mangadex_data = requests.get(
+ "https://api.mangadex.org/manga",
+ params={
+ "title": manga["title"]["romaji"],
+ "year": year,
+ },
+ ).json()["data"]
+
+ if len(mangadex_data) == 0:
+ mangadex_data = requests.get(
+ "https://api.mangadex.org/manga",
+ params={
+ "title": manga["title"]["romaji"],
+ "year": year,
+ },
+ ).json()["data"]
+
+ return mangadex_data
+
+
def manga_to_html(releasing_outdated_manga, show_missing):
current_html = []
ids = []
@@ -35,29 +63,7 @@ def manga_to_html(releasing_outdated_manga, show_missing):
mangadex_id = None
if mangadex_data is None:
- mangadex_data = requests.get(
- "https://api.mangadex.org/manga",
- params={"title": title, "year": manga["startDate"]["year"]},
- ).json()["data"]
-
- # This is very stupid. It should never get this far, anyway.
- if len(mangadex_data) == 0:
- mangadex_data = requests.get(
- "https://api.mangadex.org/manga",
- params={
- "title": manga["title"]["romaji"],
- "year": manga["startDate"]["year"],
- },
- ).json()["data"]
-
- if len(mangadex_data) == 0:
- mangadex_data = requests.get(
- "https://api.mangadex.org/manga",
- params={
- "title": manga["title"]["romaji"],
- "year": manga["startDate"]["year"],
- },
- ).json()["data"]
+ mangadex_data = rerequest(manga, manga["startDate"]["year"])
cache.set(str(manga["id"]) + "id", mangadex_data)