drop ffhlwiki and mkmap
parent
474a374cd6
commit
9257aa01a6
93
ffhlwiki.py
93
ffhlwiki.py
|
@ -1,93 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import json
|
||||
import argparse
|
||||
from itertools import zip_longest
|
||||
from urllib.request import urlopen
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
def import_wikigps(url):
|
||||
def fetch_wikitable(url):
|
||||
f = urlopen(url)
|
||||
|
||||
soup = BeautifulSoup(f)
|
||||
|
||||
table = soup.find_all("table")[0]
|
||||
|
||||
rows = table.find_all("tr")
|
||||
|
||||
headers = []
|
||||
|
||||
data = []
|
||||
|
||||
def maybe_strip(x):
|
||||
if isinstance(x.string, str):
|
||||
return x.string.strip()
|
||||
else:
|
||||
return ""
|
||||
|
||||
for row in rows:
|
||||
tds = list([maybe_strip(x) for x in row.find_all("td")])
|
||||
ths = list([maybe_strip(x) for x in row.find_all("th")])
|
||||
|
||||
if any(tds):
|
||||
data.append(tds)
|
||||
|
||||
if any(ths):
|
||||
headers = ths
|
||||
|
||||
nodes = []
|
||||
|
||||
for d in data:
|
||||
nodes.append(dict(zip(headers, d)))
|
||||
|
||||
return nodes
|
||||
|
||||
nodes = fetch_wikitable(url)
|
||||
|
||||
aliases = {}
|
||||
|
||||
for node in nodes:
|
||||
try:
|
||||
node['MAC'] = node['MAC'].split(',')
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
node['GPS'] = node['GPS'].split(',')
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
try:
|
||||
node['Knotenname'] = node['Knotenname'].split(',')
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
nodes = zip_longest(node['MAC'], node['GPS'], node['Knotenname'])
|
||||
|
||||
for data in nodes:
|
||||
alias = {}
|
||||
|
||||
mac = data[0].strip()
|
||||
|
||||
if data[1]:
|
||||
alias['gps'] = data[1].strip()
|
||||
|
||||
if data[2]:
|
||||
alias['name'] = data[2].strip()
|
||||
|
||||
aliases[mac] = alias
|
||||
|
||||
return aliases
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
parser.add_argument('url', help='wiki URL')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
options = vars(args)
|
||||
|
||||
aliases = import_wikigps(options['url'])
|
||||
|
||||
print(json.dumps(aliases))
|
15
mkmap.sh
15
mkmap.sh
|
@ -1,15 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
DEST=$1
|
||||
|
||||
|
||||
[ "$DEST" ] || exit 1
|
||||
|
||||
cd "$(dirname "$0")"/
|
||||
|
||||
./ffhlwiki.py http://freifunk.metameute.de/wiki/Knoten > aliases_hl.json
|
||||
./ffhlwiki.py http://freifunk.metameute.de/wiki/Moelln:Knoten > aliases_moelln.json
|
||||
|
||||
./bat2nodes.py -A -a aliases.json -a aliases_hl.json -a aliases_moelln.json -d $DEST
|
Loading…
Reference in New Issue