allow nicks without gps coordinates
This commit is contained in:
parent
17e25e3a3d
commit
32ee0a7032
|
@ -388,6 +388,7 @@ function update() {
|
||||||
|
|
||||||
force.nodes(nodes)
|
force.nodes(nodes)
|
||||||
.links(links)
|
.links(links)
|
||||||
|
.alpha(0.1)
|
||||||
.start()
|
.start()
|
||||||
|
|
||||||
linkedByIndex = {}
|
linkedByIndex = {}
|
||||||
|
|
44
nodedb.py
44
nodedb.py
|
@ -1,6 +1,7 @@
|
||||||
import json
|
import json
|
||||||
from node import Node
|
from node import Node
|
||||||
from link import Link
|
from link import Link
|
||||||
|
from itertools import zip_longest
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
@ -210,28 +211,37 @@ class NodeDB:
|
||||||
nodes = fetch_wikitable(url)
|
nodes = fetch_wikitable(url)
|
||||||
|
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if not ('MAC' in node and 'GPS' in node):
|
try:
|
||||||
|
node['MAC'] = node['MAC'].split(',')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
node['GPS'] = node['GPS'].split(',')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
node['Nick'] = node['Nick'].split(',')
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
nodes = zip_longest(node['MAC'], node['GPS'], node['Nick'])
|
||||||
|
|
||||||
|
for data in nodes:
|
||||||
|
if not data[0]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
macs = [s for s in [s.strip() for s in node['MAC'].split(',')] if s]
|
|
||||||
gps = [s for s in [s.strip() for s in node['GPS'].split(',')] if s]
|
|
||||||
zipped = zip(macs, gps)
|
|
||||||
|
|
||||||
if 'Nick' in node:
|
|
||||||
names = [s for s in [s.strip() for s in node['Nick'].split(',')] if s]
|
|
||||||
if names:
|
|
||||||
zipped = zip(macs, gps, names)
|
|
||||||
|
|
||||||
for pair in zipped:
|
|
||||||
try:
|
try:
|
||||||
node = self.maybe_node_by_mac((pair[0], ))
|
node = self.maybe_node_by_mac((data[0], ))
|
||||||
except:
|
except:
|
||||||
node = Node()
|
node = Node()
|
||||||
node.add_mac(pair[0])
|
node.add_mac(data[0])
|
||||||
self._nodes.append(node)
|
self._nodes.append(node)
|
||||||
|
|
||||||
if len(pair) > 2:
|
if data[1]:
|
||||||
if pair[2]:
|
node.gps = data[1]
|
||||||
node.name = pair[2]
|
|
||||||
|
if data[2]:
|
||||||
|
node.name = data[2]
|
||||||
|
|
||||||
node.gps = pair[1]
|
|
||||||
|
|
Loading…
Reference in a new issue