Use Hood from Router XML if provided

Fixes #31
This commit is contained in:
Dominik Heidler 2017-03-21 10:06:59 +01:00
parent f7dd0d9a7f
commit b16199c8db
1 changed files with 12 additions and 6 deletions

View File

@ -59,12 +59,14 @@ def import_nodewatcher_xml(mac, xml):
router_update.update(router_info)
# keep hood up to date
if "position" in router_update:
# router has new position info from netmon
router_update["hood"] = db.hoods.find_one({"position": {"$near": {"$geometry": router_update["position"]}}})["name"]
elif router and "position" in router:
# hoods might change as well
router_update["hood"] = db.hoods.find_one({"position": {"$near": {"$geometry": router["position"]}}})["name"]
if not "hood" in router_update:
# router didn't send his hood in XML
if "position" in router_update:
# router has new position info from netmon
router_update["hood"] = db.hoods.find_one({"position": {"$near": {"$geometry": router_update["position"]}}})["name"]
elif router and "position" in router:
# hoods might change as well
router_update["hood"] = db.hoods.find_one({"position": {"$near": {"$geometry": router["position"]}}})["name"]
if router:
# statistics
@ -302,6 +304,10 @@ def parse_nodewatcher_xml(xml):
with suppress(IndexError):
router_update["community"] = tree.xpath("/data/system_data/firmware_community/text()")[0]
# data.system_data.hood
with suppress(IndexError):
router_update["hood"] = tree.xpath("/data/system_data/hood/text()")[0].lower()
# data.system_data.status_text
with suppress(IndexError):
router_update["system"]["status_text"] = tree.xpath("/data/system_data/status_text/text()")[0]