Skip to content

Commit ef814d2

Browse files
Paul JenningsPaul Jennings
authored andcommitted
Added basic command line usage, changed default logging level to warning, and fixed some data parsing issues.
1 parent 9f75f8e commit ef814d2

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

TStat.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,14 @@ def age(self):
6262
return datetime.datetime.now()-self.time
6363

6464
class TStat:
65-
def __init__(self, address, cacheExpiry=5, api=None, logger=None):
65+
def __init__(self, address, cacheExpiry=5, api=None, logger=None, logLevel=None):
6666
self.address = address
6767
self.setCacheExpiry(cacheExpiry)
6868
self.cache = {}
6969
if logger is None:
70-
logging.basicConfig(level=logging.DEBUG)
70+
if logLevel is None:
71+
logLevel = logging.WARNING
72+
logging.basicConfig(level=logLevel)
7173
self.logger = logging.getLogger('TStat')
7274
else:
7375
self.logger = logger
@@ -147,7 +149,10 @@ def _get(self, key, raw=False):
147149
# Allow mappings to subdictionaries in json data
148150
# e.g. 'today/heat_runtime' from '/tstat/datalog'
149151
for key in getter[1].split("/"):
150-
response = response[key]
152+
try:
153+
response = response[key]
154+
except:
155+
pass
151156

152157
#response = response[getter[1]]
153158

@@ -247,3 +252,14 @@ def setCloudMode(self, state=True):
247252
if not state:
248253
command = "off"
249254
return self._post("/cloud/mode", {'command': command})
255+
256+
def main():
257+
import sys
258+
addr = sys.argv[1]
259+
t = TStat(addr)
260+
for cmd in sys.argv[2:]:
261+
result = eval("t.%s()" % cmd)
262+
print "%s: %s" % (cmd, result)
263+
264+
if __name__ == '__main__':
265+
main()

0 commit comments

Comments
 (0)