python_reference/useful_scripts/conc_gzip_files.py
Tim Gates a066dc35fe
docs: Fix a few typos
There are small typos in:
- tutorials/installing_scientific_packages.md
- tutorials/sqlite3_howto/README.md
- tutorials/sqlite3_howto/code/update_or_insert_records.py
- useful_scripts/conc_gzip_files.py

Fixes:
- Should read `existing` rather than `exisiting`.
- Should read `conveniently` rather than `conviniently`.
- Should read `calculate` rather than `calulate`.
- Should read `accommodate` rather than `accomodate`.
2022-06-27 13:19:05 +10:00

34 lines
1.1 KiB
Python

# Sebastian Raschka 03/2014
import gzip
import shutil
import os
#import pyprind
def conc_gzip_files(in_dir, out_file, append=False, print_progress=True):
""" Reads contents from gzipped ASCII or UTF-8 files, decodes them, and
appends the lines to one output file.
Keyword arguments:
in_dir (str): Path of the directory with the gzip-files
out_file (str): Path to the resulting file
append (bool): If true, it appends contents to an existing file,
else creates a new output file.
print_progress (bool): prints progress bar if true.
"""
write_mode = 'wb'
gzips = [os.path.join(in_dir, i) for i in os.listdir(in_dir) if i.endswith('.gz')]
#if print_progress:
# pbar = pyprind.ProgBar(len(gzips))
with open(out_file, 'ab' if append else 'wb') as ofile:
for f in gzips:
with gzip.open(f, 'rb') as gzipf:
shutil.copyfileobj(gzipf, ofile)
#if print_progress:
# pbar.update()
if __name__ == '__main__':
conc_gzip_files('/home/usr/my_dir', '/home/usr/test.txt')