From 32ee0a7032db6e6cd9f29e21cfd2ec95bfff8df4 Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Wed, 6 Jun 2012 21:43:13 +0200 Subject: [PATCH] allow nicks without gps coordinates --- html/force.js | 1 + nodedb.py | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/html/force.js b/html/force.js index 8444699..af24b91 100644 --- a/html/force.js +++ b/html/force.js @@ -388,6 +388,7 @@ function update() { force.nodes(nodes) .links(links) + .alpha(0.1) .start() linkedByIndex = {} diff --git a/nodedb.py b/nodedb.py index 7e799dc..a37fe5f 100644 --- a/nodedb.py +++ b/nodedb.py @@ -1,6 +1,7 @@ import json from node import Node from link import Link +from itertools import zip_longest from bs4 import BeautifulSoup from urllib.request import urlopen @@ -210,28 +211,37 @@ class NodeDB: nodes = fetch_wikitable(url) for node in nodes: - if not ('MAC' in node and 'GPS' in node): - continue + try: + node['MAC'] = node['MAC'].split(',') + except KeyError: + pass - 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) + try: + node['GPS'] = node['GPS'].split(',') + except KeyError: + pass - 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) + 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 - for pair in zipped: try: - node = self.maybe_node_by_mac((pair[0], )) + node = self.maybe_node_by_mac((data[0], )) except: node = Node() - node.add_mac(pair[0]) + node.add_mac(data[0]) self._nodes.append(node) - if len(pair) > 2: - if pair[2]: - node.name = pair[2] + if data[1]: + node.gps = data[1] + + if data[2]: + node.name = data[2] - node.gps = pair[1]