Skip to content

Instantly share code, notes, and snippets.

@matthew-brett
Created April 10, 2024 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthew-brett/c905d464520db530935eb6c7b79d4736 to your computer and use it in GitHub Desktop.
Save matthew-brett/c905d464520db530935eb6c7b79d4736 to your computer and use it in GitHub Desktop.
Uznip submissions
#!/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