Skip to content

Instantly share code, notes, and snippets.

@danmarinescu
Created January 27, 2017 10:57
Show Gist options
  • Save danmarinescu/1fa641d5ea6e11f1ade5f7208a5cd3b1 to your computer and use it in GitHub Desktop.
Save danmarinescu/1fa641d5ea6e11f1ade5f7208a5cd3b1 to your computer and use it in GitHub Desktop.
#!/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