allow nicks without gps coordinates

This commit is contained in:
Nils Schneider 2012-06-06 21:43:13 +02:00
parent 17e25e3a3d
commit 32ee0a7032
2 changed files with 27 additions and 16 deletions

View file

@ -388,6 +388,7 @@ function update() {
force.nodes(nodes) force.nodes(nodes)
.links(links) .links(links)
.alpha(0.1)
.start() .start()
linkedByIndex = {} linkedByIndex = {}

View file

@ -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:
continue node['MAC'] = node['MAC'].split(',')
except KeyError:
pass
macs = [s for s in [s.strip() for s in node['MAC'].split(',')] if s] try:
gps = [s for s in [s.strip() for s in node['GPS'].split(',')] if s] node['GPS'] = node['GPS'].split(',')
zipped = zip(macs, gps) except KeyError:
pass
if 'Nick' in node: try:
names = [s for s in [s.strip() for s in node['Nick'].split(',')] if s] node['Nick'] = node['Nick'].split(',')
if names: except KeyError:
zipped = zip(macs, gps, names) pass
nodes = zip_longest(node['MAC'], node['GPS'], node['Nick'])
for data in nodes:
if not data[0]:
continue
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]