Skip to content

Commit

Permalink
removed fetch content error and fixed flake8 R502
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonzorn committed Jul 22, 2024
1 parent 082d1b7 commit 12f2bc3
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 135 deletions.
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,20 @@ def start_check_for_updates_thread(self):
self._update_checker.wait()
self._update_checker.start()

def check_for_updates(self):
def check_for_updates(self) -> str | None:
response = get_html(
f"{GITHUB_REPO}/releases",
params={"per_page": 2},
content_type="json",
)
if not response:
return
return None
latest_version = None
for release in response:
version = release["tag_name"]
if APP_BRANCH in version:
return version
latest_version = version
return latest_version

def show_update_info(self, result):
info_bar_title = translate(
Expand Down
2 changes: 0 additions & 2 deletions nlightreader/consts/files/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from qfluentwidgets import FluentIconBase, getIconColor, Theme

from data import resource


class LangIcons:
Gb = ":/lang_icons/icons/lang/gb.svg"
Expand Down
3 changes: 2 additions & 1 deletion nlightreader/parsers/combined/lib/lib_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def get_manga(self, manga: Manga) -> Manga:

def search_manga(self, form: RequestForm) -> list[Manga]:
url = f"{self.url_api}/{self.content_name}"
mangas = []
params = {
"site_id[]": self.site_id,
"sort_by": form.get_order_id(),
Expand All @@ -44,6 +43,8 @@ def search_manga(self, form: RequestForm) -> list[Manga]:
cookies=cookies,
content_type="json",
)

mangas = []
if response:
for i in response.get("data"):
manga = Manga(
Expand Down
4 changes: 3 additions & 1 deletion nlightreader/parsers/combined/shikimori/shikimori_anime.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def search_manga(self, form: RequestForm):
params=params,
content_type="json",
)

mangas = []
if response:
for i in response:
Expand Down Expand Up @@ -97,7 +98,8 @@ def get_character(self, character: Character) -> Character:
url = f"{self.url_api}/characters/{character.content_id}"
response = get_html(url, headers=self.headers, content_type="json")
if response:
character.description = response.get("description")
if description := response.get("description"):
character.description = description
return character

def get_preview(self, manga: Manga):
Expand Down
9 changes: 3 additions & 6 deletions nlightreader/parsers/combined/shikimori/shikimori_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,9 @@ def get_manga(self, manga: Manga) -> Manga:
def get_character(self, character: Character) -> Character:
url = f"{self.url_api}/characters/{character.content_id}"
response = get_html(url, headers=self.headers, content_type="json")
if not response:
return character

description = response.get("description")
if description:
character.description = description
if response:
if description := response.get("description"):
character.description = description
return character

def get_preview(self, manga: Manga):
Expand Down
13 changes: 6 additions & 7 deletions nlightreader/parsers/combined/shikimori/shikimori_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
URL_SHIKIMORI_TOKEN,
)
from nlightreader.consts.enums import Nl
from nlightreader.exceptions.parser_content_exc import FetchContentError
from nlightreader.items import RequestForm, User, UserRate
from nlightreader.models import Manga
from nlightreader.parsers.catalog import LibParser
Expand All @@ -38,14 +37,15 @@ def search_manga(self, form: RequestForm):
url = f"{self.url_api}/users/{self.session.user.id}/manga_rates"
params = {"limit": 50, "page": form.page}
response = self.session.request("GET", url, params=params)
mangas = []
lib_list = form.lib_list
if lib_list == Nl.LibList.reading:
lib_list = "watching"
elif lib_list == Nl.LibList.re_reading:
lib_list = "rewatching"
else:
lib_list = form.lib_list.name

mangas = []
if response and (resp_json := response.json()):
for i in resp_json:
if not i.get("status") == lib_list:
Expand Down Expand Up @@ -236,9 +236,9 @@ def request(
"test" in QApplication.arguments()
or "noshiki" in QApplication.arguments()
):
raise FetchContentError
return None
if not ignore_authorize and not self.is_authorized:
raise FetchContentError
return None
try:
response = self.client.request(
method,
Expand All @@ -257,12 +257,11 @@ def request(
f"\t\tCookies: {self.client.cookies}\n"
f"\t\tJson: {json}\n",
)
raise FetchContentError

def check_auth(self):
def check_auth(self) -> bool:
url = f"{URL_SHIKIMORI_API}/users/whoami"
whoami = self.request("GET", url, ignore_authorize=True)
self.is_authorized = whoami and whoami.json()
self.is_authorized = bool(whoami) and bool(whoami.json())
return self.is_authorized

@property
Expand Down
1 change: 1 addition & 0 deletions nlightreader/parsers/combined/shikimori/shikimori_manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def search_manga(self, form: RequestForm):
params=params,
content_type="json",
)

mangas = []
if response:
for i in response:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def search_manga(self, form: RequestForm):
params=params,
content_type="json",
)

mangas = []
if response:
for i in response:
Expand Down
49 changes: 26 additions & 23 deletions nlightreader/parsers/hentai_manga/allhentai_hmanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,34 @@ def search_manga(self, form):
def get_chapters(self, manga: Manga):
url = f"{self.url}/{manga.content_id}"
response = get_html(url, headers=self.headers, content_type="text")

chapters = []
if response:
soup = BeautifulSoup(response, "html.parser")
chapters_list_item = soup.find("div", id="chapters-list")
for chapter_item in chapters_list_item.findAll(
"tr",
class_="item-row",
):
volume: str = chapter_item.get("data-vol")
chapter_num: str = chapter_item.get("data-num")
if chapter_num.isdigit():
chapter_as_num = int(chapter_num) / 10
if chapter_as_num.is_integer():
chapter_as_num = int(chapter_as_num)
chapter_num = str(chapter_as_num)
if not response:
return chapters

soup = BeautifulSoup(response, "html.parser")
chapters_list_item = soup.find("div", id="chapters-list")
for chapter_item in chapters_list_item.findAll(
"tr",
class_="item-row",
):
volume: str = chapter_item.get("data-vol")
chapter_num: str = chapter_item.get("data-num")
if chapter_num.isdigit():
chapter_as_num = int(chapter_num) / 10
if chapter_as_num.is_integer():
chapter_as_num = int(chapter_as_num)
chapter_num = str(chapter_as_num)

chapter = Chapter(
manga.content_id,
self.CATALOG_ID,
volume,
chapter_num,
"",
Nl.Language.ru,
)
chapters.append(chapter)
chapter = Chapter(
manga.content_id,
self.CATALOG_ID,
volume,
chapter_num,
"",
Nl.Language.ru,
)
chapters.append(chapter)
return chapters

def get_images(self, manga: Manga, chapter: Chapter):
Expand Down
43 changes: 23 additions & 20 deletions nlightreader/parsers/hentai_manga/nhentai_hmanga.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,30 @@ def search_manga(self, form):
params=params,
content_type="text",
)

mangas = []
if response:
soup = BeautifulSoup(response, "html.parser")
html_items = soup.findAll("div", class_="gallery")
for i in html_items:
caption_tag = i.find("div", class_="caption")
if caption_tag is not None:
name = i.find("div", class_="caption").text
cover_tag = i.find("a", {"class": "cover"})
if cover_tag is not None:
manga_id = cover_tag["href"].split("/")[-2]
if not manga_id:
continue
mangas.append(
Manga(
manga_id,
self.CATALOG_ID,
name,
"",
),
)
if not response:
return mangas

soup = BeautifulSoup(response, "html.parser")
html_items = soup.findAll("div", class_="gallery")
for i in html_items:
caption_tag = i.find("div", class_="caption")
if caption_tag is not None:
name = i.find("div", class_="caption").text
cover_tag = i.find("a", {"class": "cover"})
if cover_tag is not None:
manga_id = cover_tag["href"].split("/")[-2]
if not manga_id:
continue
mangas.append(
Manga(
manga_id,
self.CATALOG_ID,
name,
"",
),
)
return mangas

def get_chapters(self, manga: Manga):
Expand Down
27 changes: 15 additions & 12 deletions nlightreader/parsers/manga/desu_manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ def search_manga(self, form: RequestForm):
params=params,
content_type="json",
)
manga = []
if response:
for i in get_data(response, ["response"]):
manga.append(
Manga(
str(i.get("id")),
self.CATALOG_ID,
i.get("name"),
i.get("russian"),
),
)
return manga

mangas = []
if not response:
return mangas

for i in get_data(response, ["response"]):
mangas.append(
Manga(
str(i.get("id")),
self.CATALOG_ID,
i.get("name"),
i.get("russian"),
),
)
return mangas

def get_chapters(self, manga: Manga):
url = f"{self.url_api}/{manga.content_id}"
Expand Down
16 changes: 10 additions & 6 deletions nlightreader/parsers/manga/mangadex_manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,19 @@ def search_manga(self, form: RequestForm):
"pornographic",
],
}
mangas = []
response = get_html(
url,
headers=self.headers,
params=params,
content_type="json",
)
if response:
for i in get_data(response, ["data"]):
mangas.append(self.setup_manga(i))

mangas = []
if not response:
return mangas

for i in get_data(response, ["data"]):
mangas.append(self.setup_manga(i))
return mangas

def get_chapters(self, manga: Manga):
Expand Down Expand Up @@ -328,8 +331,9 @@ def auth_login(self, params):
self.refresh_token()

def get(self, url, params=None):
if self.is_authorized:
return get_html(url, params=params, headers=self.headers)
if not self.is_authorized:
return None
return get_html(url, params=params, headers=self.headers)

@property
def headers(self):
Expand Down
23 changes: 13 additions & 10 deletions nlightreader/parsers/manga/remanga_manga.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ def search_manga(self, form: RequestForm):
params=params,
content_type="json",
)

mangas = []
if response:
for i in response.get("content"):
manga_id = i.get("dir")
name = i.get("en_name")
russian = i.get("rus_name")
manga = Manga(manga_id, self.CATALOG_ID, name, russian)
manga.kind = Nl.MangaKind.from_str(i.get("type"))
manga.score = float(i.get("avg_rating"))
manga.preview_url = i.get("img").get("high")
mangas.append(manga)
if not response:
return mangas

for i in response.get("content"):
manga_id = i.get("dir")
name = i.get("en_name")
russian = i.get("rus_name")
manga = Manga(manga_id, self.CATALOG_ID, name, russian)
manga.kind = Nl.MangaKind.from_str(i.get("type"))
manga.score = float(i.get("avg_rating"))
manga.preview_url = i.get("img").get("high")
mangas.append(manga)
return mangas

def get_chapters(self, manga: Manga) -> list[Chapter]:
Expand Down
Loading

0 comments on commit 12f2bc3

Please sign in to comment.