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

Support import from WACZ files #16

Merged
merged 2 commits into from
Oct 20, 2023
Merged

Conversation

edsu
Copy link
Contributor

@edsu edsu commented Oct 20, 2023

Since WACZ files are ZIP files that contain WARC files at a particular directory location we can import them fairly easily, without requiring the ZIP file to be uncompressed to disk first.

The added test file tests/scoop.wacz was created using the scoop utility:

$ scoop https://github.com/Florents-Tselai/WarcDB

The only caveat is that loading WACZs from a URL is not yet supported.

Closes #15

Since WACZ files are ZIP files that contain WARC files at a particular
directory location we can import them fairly easily, without requiring
the ZIP file to be uncompressed to disk first.

The added tests/scoop.wacz was created using the
[scoop](https://github.com/harvard-lil/scoop) utility:

```shell
$ scoop https://github.com/Florents-Tselai/WarcDB
```

Closes Florents-Tselai#15
import pytest
import sqlite_utils
from unittest import TestCase
from click.testing import CliRunner
from warcdb import warcdb_cli
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just removing TestCase which was not used, and sorting them.

wacz = zipfile.ZipFile(f)
warcs = filter(lambda f: f.filename.endswith('warc.gz'), wacz.infolist())
for warc in warcs:
yield from tqdm(ArchiveIterator(wacz.open(warc.filename, 'r'), arc2warc=True), desc=warc.filename)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This picks the WARC files out of the WACZ's archive directory, and creates an ArchiveIterator for each one.

@edsu edsu marked this pull request as ready for review October 20, 2023 14:11
@Florents-Tselai Florents-Tselai merged commit 7ac8fdb into Florents-Tselai:main Oct 20, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WACZ support?
2 participants