Created
February 8, 2019 21:16
-
-
Save cschaba/fe290b107ed9f1912f581e1ed5a950d6 to your computer and use it in GitHub Desktop.
Pythonista extension script to decompress GZIP file and then open in ...
This file contains hidden or 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
# coding: utf-8 | |
# PYTHONISTA extension - uncompress GZIP Files | |
import appex | |
import console | |
import re | |
import gzip | |
import os.path | |
import shutil | |
def main(): | |
if not appex.is_running_extension(): | |
print('This script is intended to be run from the sharing extension.') | |
return | |
for file in appex.get_file_paths(): | |
if not file: | |
print('No file found.') | |
return | |
# decompress file | |
file2 = os.path.splitext(os.path.basename(file))[0] | |
with gzip.open(file, "rb") as i_file: | |
with gzip.open(file2, "wb") as o_file: | |
shutil.copyfileobj(i_file, o_file) | |
# open decompressed file in other app | |
console.open_in(file2) | |
# cleanup the decompressed files | |
os.unlink(file2) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment