-
Notifications
You must be signed in to change notification settings - Fork 0
/
catch-all
executable file
·41 lines (30 loc) · 1.25 KB
/
catch-all
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
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
""" OPK push skeleton model code for Python.
Here are some test results:
$ echo '{"temperature":1.0,"conductivity":2.0,"depth":3.0}' | ./push_phant_json -v
LOADED JSON DATA: OrderedDict([(u'temperature', 1.0), (u'conductivity', 2.0), (u'depth', 3.0)])
POSTING: https://data.sparkfun.com/input/jqERJOgdYKuyw09Zm8xb?private_key=XXXXXXXXXXXXXXXXXXXX&temperature=1.0&conductivity=2.0&depth=3.0
RESPONSE: <addinfourl at 139956652527344 whose fp = <socket._fileobject object at 0x7f4a3371cf50>>
"""
import sys, os, argparse, glob, json, urllib2
from collections import OrderedDict
LOGFILE = sys.stderr
IN_STREAM = sys.stdin
OUT_STREAM = sys.stdout
# parse the command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity")
args = parser.parse_args()
# process the input
try:
#decode into and ordered dictionary, assuming JSON document
data = json.load(IN_STREAM, object_pairs_hook = OrderedDict)
for key, val in data.items():
if key=="error":
print "error=", val
#print (key,val)
except Exception, exc:
LOGFILE.write("ERROR: %s" % exc)
finally:
LOGFILE.close()
IN_STREAM.close()