ffmap-backend/alfred.py
Daniel Ehlers 2c79b1d91c alfred: Retrieve aliases from alfred and integrate batadv-vis.
Extending the visualisation data sources by the new batadv-vis,
which itself base ontop of alfred. Also extending the aliases import
by parsing informations from alfred. The last part is possible
through the preprocessing of data with alfred-json, so we don't
need to process the 'broken' format alfred itself supports.

This patch needs batadv-vis and tcatm/alfred-json in the PATH.
2014-01-30 22:11:01 +01:00

29 lines
840 B
Python
Executable file

#!/usr/bin/env python3
import subprocess
import json
class alfred:
def __init__(self,request_data_type = 158):
self.request_data_type = request_data_type
def aliases(self):
output = subprocess.check_output(["alfred-json","-r",str(self.request_data_type),"-f","json"])
alfred_data = json.loads(output.decode("utf-8"))
alias = {}
for mac,node in alfred_data.items():
node_alias = {}
if 'location' in node:
node_alias['gps'] = str(node['location']['latitude']) + ' ' + str(node['location']['longitude'])
if 'hostname' in node:
node_alias['name'] = node['hostname']
elif 'name' in node:
node_alias['name'] = node['name']
if len(node_alias):
alias[mac] = node_alias
return alias
if __name__ == "__main__":
ad = alfred()
al = ad.alias()
print(al)