Skip to content

Commit

Permalink
Merge pull request #3 from thalida/0.1.4
Browse files Browse the repository at this point in the history
0.1.4
  • Loading branch information
thalida authored Sep 2, 2024
2 parents 3a84a08 + f3b9b1e commit 666e488
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
26 changes: 18 additions & 8 deletions ao3_sync/api/resources/bookmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ def fetch_page(

history = self._client.get_history()

bookmarks_page: Any = self._client.get_or_fetch(
self.URL_PATH,
query_params=query_params,
)
try:
bookmarks_page: Any = self._client.get_or_fetch(
self.URL_PATH,
query_params=query_params,
)
except Exception as e:
self._client._debug_error(f"Failed to fetch bookmarks page {page}: {e}")
return []

bookmark_element_list = parsel.Selector(bookmarks_page).css("ol.bookmark > li")
bookmark_list: list[Bookmark] = []
Expand Down Expand Up @@ -206,10 +210,16 @@ def fetch_page_count(self):
Returns:
num_pages (int): Number of bookmark pages
"""
first_page: Any = self._client.get_or_fetch(
self.URL_PATH,
query_params={"page": 1, "user_id": self._client.auth.username, "sort_column": "created_at"},
)

try:
first_page: Any = self._client.get_or_fetch(
self.URL_PATH,
query_params={"page": 1, "user_id": self._client.auth.username, "sort_column": "created_at"},
)
except Exception as e:
self._client._debug_error(f"Failed to fetch first bookmarks page: {e}")
return 0

pagination = parsel.Selector(first_page).css("ol.pagination li").getall()

if len(pagination) < 3:
Expand Down
7 changes: 6 additions & 1 deletion ao3_sync/api/resources/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ def fetch_works(self, series_id: str) -> list[str]:
works_list (list[str]): List of work IDs in the series
"""

series_page: Any = self._client.get_or_fetch(f"{self.URL_PATH}/{series_id}")
try:
series_page: Any = self._client.get_or_fetch(f"{self.URL_PATH}/{series_id}")
except Exception as e:
self._client._debug_error(f"Failed to fetch series {series_id}: {e}")
return []

works_element_list = parsel.Selector(series_page).css("ul.series.work > li")

works_list: list[str] = []
Expand Down
14 changes: 11 additions & 3 deletions ao3_sync/api/resources/works.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def fetch_download_links(
download_links (list[str]): List of download links
"""
work_url = f"{self.URL_PATH}/{work_id}"
work_page: Any = self._client.get_or_fetch(work_url)

try:
work_page: Any = self._client.get_or_fetch(work_url)
except Exception as e:
self._client._debug_error(f"Failed to fetch work {work_id}: {e}")
return []

download_links = (
parsel.Selector(work_page).css("#main ul.work.navigation li.download ul li a::attr(href)").getall()
Expand Down Expand Up @@ -88,5 +93,8 @@ def download(
download_url (str): URL of the work download file
"""
self._client._debug_log(f"Downloading {download_url} for work: {work_id}")
self._client.download_file(download_url)
self._client._debug_log("Downloaded work:", work_id)
try:
self._client.download_file(download_url)
self._client._debug_log("Downloaded work:", work_id)
except Exception as e:
self._client._debug_error(f"Failed to download work {work_id}: {e}")
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ao3-sync"
version = "0.1.3"
version = "0.1.4"
repository = "https://github.com/thalida/ao3-sync"
homepage = "https://thalida.github.io/ao3-sync/"
documentation = "https://thalida.github.io/ao3-sync/"
Expand Down

0 comments on commit 666e488

Please sign in to comment.