mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Update local crawler to new crawler structure
This commit is contained in:
parent
e21795ee35
commit
ae3d80664c
@ -56,10 +56,8 @@ class LocalCrawler(Crawler):
|
||||
else:
|
||||
self._block_size = 1024**2 # 1 MiB
|
||||
|
||||
async def crawl(self) -> None:
|
||||
async def _run(self) -> None:
|
||||
await self._crawl_path(self._target, PurePath())
|
||||
if self.error_free:
|
||||
await self.cleanup()
|
||||
|
||||
@anoncritical
|
||||
async def _crawl_path(self, path: Path, pure: PurePath) -> None:
|
||||
@ -69,9 +67,13 @@ class LocalCrawler(Crawler):
|
||||
await self._crawl_file(path, pure)
|
||||
|
||||
async def _crawl_dir(self, path: Path, pure: PurePath) -> None:
|
||||
cl = await self.crawl(pure)
|
||||
if not cl:
|
||||
return
|
||||
|
||||
tasks = []
|
||||
|
||||
async with self.crawl_bar(pure):
|
||||
async with cl:
|
||||
await asyncio.sleep(random.uniform(
|
||||
0.5 * self._crawl_delay,
|
||||
self._crawl_delay,
|
||||
@ -79,7 +81,6 @@ class LocalCrawler(Crawler):
|
||||
|
||||
for child in path.iterdir():
|
||||
pure_child = pure / child.name
|
||||
if self.should_crawl(child):
|
||||
tasks.append(self._crawl_path(child, pure_child))
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
@ -91,7 +92,7 @@ class LocalCrawler(Crawler):
|
||||
if not dl:
|
||||
return
|
||||
|
||||
async with self.download_bar(pure) as bar:
|
||||
async with dl as (bar, sink):
|
||||
await asyncio.sleep(random.uniform(
|
||||
0.5 * self._download_delay,
|
||||
self._download_delay,
|
||||
@ -99,7 +100,6 @@ class LocalCrawler(Crawler):
|
||||
|
||||
bar.set_total(stat.st_size)
|
||||
|
||||
async with dl as sink:
|
||||
with open(path, "rb") as f:
|
||||
while True:
|
||||
data = f.read(self._block_size)
|
||||
|
Loading…
Reference in New Issue
Block a user