forked from ffnord/ffmap-d3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bat2nodes.py
executable file
·52 lines (34 loc) · 1.14 KB
/
bat2nodes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
# TODO
# Gatewayliste
# aliases.json
import json
import fileinput
import argparse
from nodedb import NodeDB
from d3mapbuilder import D3MapBuilder
# Force encoding to UTF-8
import locale # Ensures that subsequent open()s
locale.getpreferredencoding = lambda: 'UTF-8' # are UTF-8 encoded.
import sys
sys.stdin = open('/dev/stdin', 'r')
sys.stdout = open('/dev/stdout', 'w')
sys.stderr = open('/dev/stderr', 'w')
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--aliases',
help='read aliases from FILE',
metavar='FILE')
parser.add_argument('-g', '--gateway', action='append',
help='MAC of a gateway')
parser.add_argument('batmanjson', help='output of batman vd json')
args = parser.parse_args()
options = vars(args)
db = NodeDB()
db.import_batman(list(fileinput.input(options['batmanjson'])))
db.import_wikigps("http://freifunk.metameute.de/Knoten")
if options['aliases']:
db.import_aliases(json.load(open(options['aliases'])))
if options['gateway']:
db.mark_gateways(options['gateway'])
m = D3MapBuilder(db)
print(m.build())