input alfred: unify nodeinfo and stats datatypes

rewrite
Jan-Philipp Litza 2014-07-31 11:41:26 +02:00
parent e54e7467fc
commit 446bc98403
1 changed files with 16 additions and 2 deletions

View File

@ -7,12 +7,26 @@ class Input:
def get_data(self, nodedb): def get_data(self, nodedb):
"""Add data from alfred to the supplied nodedb""" """Add data from alfred to the supplied nodedb"""
# get nodeinfo
output = subprocess.check_output([ output = subprocess.check_output([
"alfred-json", "alfred-json",
"-r", str(self.request_data_type), "-r", str(self.request_data_type),
"-f", "json", "-f", "json",
]) ])
alfred_data = json.loads(output.decode("utf-8")) nodeinfo = json.loads(output.decode("utf-8"))
for mac, node in alfred_data.items(): # get statistics
output = subprocess.check_output([
"alfred-json",
"-r", str(self.request_data_type+1),
"-f", "json",
])
statistics = json.loads(output.decode("utf-8"))
# merge statistics into nodeinfo to be compatible with earlier versions
for mac, node in statistics.items():
if mac in nodeinfo:
nodeinfo[mac]['statistics'] = statistics[mac]
for mac, node in nodeinfo.items():
nodedb.add_or_update([mac], node) nodedb.add_or_update([mac], node)