From b4099ab2e81afe84b6ce43693f945f612e0e7dfc Mon Sep 17 00:00:00 2001 From: 100gle Date: Wed, 7 Jun 2023 15:41:15 +0800 Subject: [PATCH] ci(lint): fix lambda assignment error --- src/module/parser/analyser/bgm_parser.py | 3 +- src/module/parser/analyser/tmdb_parser.py | 41 +++++++++++++++-------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/module/parser/analyser/bgm_parser.py b/src/module/parser/analyser/bgm_parser.py index af345270..eb87f509 100644 --- a/src/module/parser/analyser/bgm_parser.py +++ b/src/module/parser/analyser/bgm_parser.py @@ -1,7 +1,8 @@ from module.network import RequestContent -search_url = lambda e: f"https://api.bgm.tv/search/subject/{e}?responseGroup=large" +def search_url(e): + return f"https://api.bgm.tv/search/subject/{e}?responseGroup=large" def bgm_parser(title): diff --git a/src/module/parser/analyser/tmdb_parser.py b/src/module/parser/analyser/tmdb_parser.py index 65f8f8eb..788c5528 100644 --- a/src/module/parser/analyser/tmdb_parser.py +++ b/src/module/parser/analyser/tmdb_parser.py @@ -2,8 +2,8 @@ import re import time from dataclasses import dataclass -from module.network import RequestContent from module.conf import TMDB_API +from module.network import RequestContent @dataclass @@ -16,16 +16,15 @@ class TMDBInfo: year: str -LANGUAGE = { - "zh": "zh-CN", - "jp": "ja-JP", - "en": "en-US" -} +LANGUAGE = {"zh": "zh-CN", "jp": "ja-JP", "en": "en-US"} -search_url = lambda e: \ - f"https://api.themoviedb.org/3/search/tv?api_key={TMDB_API}&page=1&query={e}&include_adult=false" -info_url = lambda e, key: \ - f"https://api.themoviedb.org/3/tv/{e}?api_key={TMDB_API}&language={LANGUAGE[key]}" + +def search_url(e): + return f"https://api.themoviedb.org/3/search/tv?api_key={TMDB_API}&page=1&query={e}&include_adult=false" + + +def info_url(e, key): + return f"https://api.themoviedb.org/3/tv/{e}?api_key={TMDB_API}&language={LANGUAGE[key]}" def is_animation(tv_id, language) -> bool: @@ -42,7 +41,7 @@ def get_season(seasons: list) -> int: for season in seasons: if re.search(r"第 \d 季", season.get("season")) is not None: date = season.get("air_date").split("-") - [year, _ , _] = date + [year, _, _] = date now_year = time.localtime().tm_year if int(year) <= now_year: return int(re.findall(r"\d", season.get("season"))[0]) @@ -63,16 +62,30 @@ def tmdb_parser(title, language) -> TMDBInfo | None: break url_info = info_url(id, language) info_content = req.get_json(url_info) - season = [{"season": s.get("name"), "air_date": s.get("air_date"), "poster_path": s.get("poster_path")} for s in info_content.get("seasons")] + season = [ + { + "season": s.get("name"), + "air_date": s.get("air_date"), + "poster_path": s.get("poster_path"), + } + for s in info_content.get("seasons") + ] last_season = get_season(season) original_title = info_content.get("original_name") official_title = info_content.get("name") year_number = info_content.get("first_air_date").split("-")[0] - return TMDBInfo(id, official_title, original_title, season, last_season, str(year_number)) + return TMDBInfo( + id, + official_title, + original_title, + season, + last_season, + str(year_number), + ) else: return None if __name__ == '__main__': title = "鬼灭之刃" - print(tmdb_parser(title, "zh")) \ No newline at end of file + print(tmdb_parser(title, "zh"))