Skip to content

Commit

Permalink
Merge pull request #48 from openzim/overwrite
Browse files Browse the repository at this point in the history
Add CLI argument --overwrite to delete existing ZIM
  • Loading branch information
benoit74 authored Dec 19, 2024
2 parents 44517dc + a5e08a1 commit 5728331
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix support for all FCC supported spoken languages (#20)
- Remove incomplete support of dark mode, no more white on white text: not readable (#33)

### Added

- Add --overwrite CLI argument to not fail when ZIM already exists (#44)

## [1.1.1] - 2023-12-18

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions scraper/src/fcc2zim/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def main():
action="version",
version=f"fcc2zim {VERSION}",
)
parser.add_argument(
"--overwrite",
help="Do not fail if ZIM already exists, overwrite it",
action="store_true",
dest="overwrite_existing_zim",
)

args = parser.parse_args()

Expand All @@ -163,6 +169,7 @@ def main():
course_csv=args.course,
zip_main_path=args.zip_path,
zip_i18n_path=args.i18n_zip_path,
overwrite_existing_zim=args.overwrite_existing_zim,
start_date=datetime.date.today(),
)

Expand Down
3 changes: 2 additions & 1 deletion scraper/src/fcc2zim/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
course_csv: str,
zip_main_path: str | None,
zip_i18n_path: str | None,
overwrite_existing_zim: bool,
start_date: datetime.date,
):
self.do_fetch = do_fetch
Expand Down Expand Up @@ -104,7 +105,7 @@ def __init__(
self.zim_path = self.output.joinpath(self.zim_path)

if self.zim_path.exists():
if not self.force:
if not (self.force or overwrite_existing_zim):
raise ValueError(f"ZIM file {self.zim_path} already exist.")
Global.logger.info(f"Removing existing ZIM file {self.zim_path}")
self.zim_path.unlink()
Expand Down
2 changes: 2 additions & 0 deletions scraper/tests/test_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def create_scraper(
course_csv="regular-expressions,basic-javascript",
zip_main_path: str | None = None,
zip_i18n_path: str | None = None,
overwrite_existing_zim: bool = False,
start_date: datetime.date = DEFAULT_START_DATE,
):
return Scraper(
Expand All @@ -112,6 +113,7 @@ def create_scraper(
course_csv=course_csv,
zip_main_path=zip_main_path,
zip_i18n_path=zip_i18n_path,
overwrite_existing_zim=overwrite_existing_zim,
start_date=start_date,
)

Expand Down

0 comments on commit 5728331

Please sign in to comment.