Skip to content

Commit a3fad14

Browse files
committed
refactor: callback manager의 콜백 생성 메서드 함수의 이름을 create로 변경
1 parent 646afc1 commit a3fad14

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

WebtoonScraper/scrapers/_callback_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, default_context: dict | None = None):
3333
self.callbacks: defaultdict[str, list[Callback]] = defaultdict(list)
3434
self.default_context = default_context or {}
3535

36-
def default(
36+
def create(
3737
self,
3838
message: str | Callable | None = None,
3939
extra_context: dict | None = None,

WebtoonScraper/scrapers/_scraper.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ async def async_download_webtoon(self, download_range: RangeType = None) -> None
369369
if not getattr(self, "bearer", True): # bearer가 있는데 None인 경우
370370
logger.debug("Bearer is not set")
371371

372-
async with self.callbacks.context("setup", start_default=self.callbacks.default("Gathering data...")):
372+
async with self.callbacks.context("setup", start_default=self.callbacks.create("Gathering data...")):
373373
await self.fetch_all()
374374

375375
webtoon_directory = self._prepare_directory()
@@ -384,7 +384,7 @@ async def async_download_webtoon(self, download_range: RangeType = None) -> None
384384
if self._download_status != "nothing":
385385
logger.warning(f"Program status is not usual: {self._download_status!r}")
386386
self._download_status = "downloading"
387-
async with self.callbacks.context("download_episode", end_default=self.callbacks.default("The webtoon {scraper.title} download ended.")):
387+
async with self.callbacks.context("download_episode", end_default=self.callbacks.create("The webtoon {scraper.title} download ended.")):
388388
await self._download_episodes(download_range, webtoon_directory)
389389
webtoon_directory = self._post_process_directory(webtoon_directory)
390390

@@ -620,7 +620,7 @@ async def _episode_skipped(self, reason: DownloadStatus, description: str, *, no
620620
if no_progress:
621621
await self.callbacks.async_callback(
622622
"download_skipped",
623-
self.callbacks.default(
623+
self.callbacks.create(
624624
msg_format,
625625
level=level,
626626
),
@@ -629,7 +629,7 @@ async def _episode_skipped(self, reason: DownloadStatus, description: str, *, no
629629
else:
630630
await self.callbacks.async_callback(
631631
"download_skipped",
632-
self.callbacks.default(
632+
self.callbacks.create(
633633
msg_format,
634634
progress_update="{short_ep_title} skipped",
635635
level=level,
@@ -683,7 +683,7 @@ async def _download_episode(self, episode_no: int, context: dict) -> None:
683683

684684
# send done callback message
685685
self.download_status[episode_no] = "downloaded"
686-
await self.callbacks.async_callback("download_completed", self.callbacks.default("[{total_ep}/{episode_no1}] {short_ep_title!r} downloaded", progress_update="{short_ep_title} downloaded"), **context)
686+
await self.callbacks.async_callback("download_completed", self.callbacks.create("[{total_ep}/{episode_no1}] {short_ep_title!r} downloaded", progress_update="{short_ep_title} downloaded"), **context)
687687

688688
async def _download_episode_images(self, episode_no: int, image_urls: list[str], episode_directory: Path) -> None:
689689
async with asyncio.TaskGroup() as group:
@@ -980,7 +980,7 @@ async def check_episode_directory(
980980
not_empty_dir = False
981981

982982
# 다운로드 직전에 메시지를 보냄
983-
await scraper.callbacks.async_callback("downloading", scraper.callbacks.default(progress_update="downloading {short_ep_title}"), **context)
983+
await scraper.callbacks.async_callback("downloading", scraper.callbacks.create(progress_update="downloading {short_ep_title}"), **context)
984984

985985
# fetch image urls
986986
time.sleep(scraper.download_interval) # 실질적인 외부 요청을 보내기 직전에만 interval을 넣음.
@@ -1001,7 +1001,7 @@ async def check_episode_directory(
10011001
scraper.download_status[episode_no] = "failed"
10021002
await scraper.callbacks.async_callback(
10031003
"download_failed",
1004-
callback or scraper.callbacks.default(
1004+
callback or scraper.callbacks.create(
10051005
"[{total_ep}/{episode_no1}] The episode '{short_ep_title}' is failed {description}",
10061006
progress_update="{short_ep_title} skipped",
10071007
level="warning",

0 commit comments

Comments
 (0)