-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaths.py
More file actions
32 lines (28 loc) · 743 Bytes
/
paths.py
File metadata and controls
32 lines (28 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import read_ga
from dateutil.parser import parse
from datetime import timedelta
import json
import sys
import datetime
import jsonpath_rw
from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)
paths = sys.argv[1:]
parsers = [jsonpath_rw.parse(p) for p in paths]
def enlist(chunk, parsers):
res = []
for p in parsers:
matches = p.find(chunk)
if len(matches) > 0:
res.append(matches[0].value)
else:
res.append("missing")
return res
for line in sys.stdin:
try:
ch = json.loads(line)
outp = enlist(ch, parsers)
print json.dumps(outp)
except Exception, e:
sys.stderr.write("Skipping: ", line)
sys.stderr.write(e)