Skip to content

Instantly share code, notes, and snippets.

@nermolov
Last active October 3, 2015 20:44
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 nermolov/b4e5a8ea9e8c7dd78fc5 to your computer and use it in GitHub Desktop.
Save nermolov/b4e5a8ea9e8c7dd78fc5 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys, getopt
import json
from pprint import pprint
def main(argv):
inputfile = ''
try:
opts, args = getopt.getopt(argv,"hi:",["ifile="])
except getopt.GetoptError:
print 'test.py -i <inputfile>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -i <inputfile>'
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
print 'Input file is ', inputfile
test = inputfile
print test
with open('{0}'.format(inputfile)) as data_file:
data = json.load(data_file)
pprint(data)
if __name__ == "__main__":
main(sys.argv[1:])
#!/bin/bash
python test.py -i $1 | grep text | sed -e s/u\'text\'\:// -e s/' 'u\'// -e s/\'},//g -e s/\'}]}//g -e "s/^[[:space:]]*$/\\n/g;s/[[:space:]]*$//" | sed ':a;N;$!ba;s/\n\n/ /g'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment