Created
January 27, 2017 10:57
-
-
Save danmarinescu/1fa641d5ea6e11f1ade5f7208a5cd3b1 to your computer and use it in GitHub Desktop.
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/python | |
import sys, getopt | |
import subprocess | |
def main(argv): | |
inputfile = '' | |
outputfile = '' | |
try: | |
opts, args = getopt.getopt(argv,"h",["help"]) | |
except getopt.GetoptError: | |
print 'test.py <url> [outputfile]' | |
sys.exit(2) | |
for opt, arg in opts: | |
if opt == '-h': | |
print 'test.py <url> [outputfile]' | |
sys.exit() | |
if not args: | |
print 'test.py <url> [outputfile]' | |
url = args[0] | |
p1 = subprocess.Popen(["http", url], stdout=subprocess.PIPE) | |
p2 = subprocess.Popen(["gunzip", "-c"], stdin=p1.stdout, stdout=subprocess.PIPE) | |
if len(args) > 1: | |
outputfilename = args[1] | |
with open(outputfilename, 'w') as outputfile: | |
p3 = subprocess.Popen(["jq", "."], stdin=p2.stdout, stdout=outputfile) | |
else: | |
p3 = subprocess.Popen(["jq", "."], stdin=p2.stdout) | |
p1.wait() | |
if __name__ == "__main__": | |
main(sys.argv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment