Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always report summary #77

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion il_supermarket_scarper/engines/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def scrape(
limit=limit, files_types=files_types, store_id=store_id
)
self.make_storage_path_dir()
completed_successfully = True
results = []
try:
results = self._scrape(
Expand All @@ -264,12 +265,15 @@ def scrape(
suppress_exception=suppress_exception,
)
self.on_download_completed(results=results)
self.on_scrape_completed(self.get_storage_path())
except Exception as e: # pylint: disable=broad-exception-caught
if not suppress_exception:
raise e
Logger.warning(f"Suppressing exception! {e}")
completed_successfully = False
finally:
self.on_scrape_completed(
self.get_storage_path(), completed_successfully=completed_successfully
)
self._post_scraping()

return results
Expand Down
6 changes: 4 additions & 2 deletions il_supermarket_scarper/utils/scraper_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ def _add_downloaded_files_to_list(self, results, **_):
self.database.insert_documents(self.VERIFIED_DOWNLOADS, documents)

@lock_by_string()
def on_scrape_completed(self, folder_name):
def on_scrape_completed(self, folder_name, completed_successfully=True):
"""Report when scraping is completed."""
self._insert_an_update(
ScraperStatus.ESTIMATED_SIZE, folder_size=log_folder_details(folder_name)
ScraperStatus.ESTIMATED_SIZE,
folder_size=log_folder_details(folder_name),
completed_successfully=completed_successfully,
)

@lock_by_string()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
tests_require=dev_required,
extras_require={"test": ["pytest", "pytest-xdist"]},
# *strongly* suggested for sharing
version="0.5.2",
version="0.5.3",
# The license can be anything you like
license="MIT",
description="python package that implement a scraping for israeli supermarket data",
Expand Down
Loading