Created
April 10, 2024 15:55
-
-
Save matthew-brett/c905d464520db530935eb6c7b79d4736 to your computer and use it in GitHub Desktop.
Uznip submissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from pathlib import Path | |
import zipfile | |
from argparse import ArgumentParser, RawDescriptionHelpFormatter | |
def unpack_zip(zip_path, out_dir): | |
out_path = out_dir / zip_path.stem | |
if not out_path.is_dir(): | |
out_path.mkdir(parents=True, exist_ok=True) | |
with zipfile.ZipFile(zip_path, 'r') as zip_ref: | |
zip_ref.extractall(out_path) | |
def get_parser(): | |
parser = ArgumentParser(description=__doc__, # Usage from docstring | |
formatter_class=RawDescriptionHelpFormatter) | |
parser.add_argument('zips', nargs='+', | |
help='Zip filenames to unpack') | |
parser.add_argument('-d', '--output-dir', default='.', | |
help='Output directory') | |
return parser | |
def main(): | |
parser = get_parser() | |
args = parser.parse_args() | |
out_dir = Path(args.output_dir) | |
for zip_fname in args.zips: | |
unpack_zip(Path(zip_fname), out_dir) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment