lifo-dijkstraserv/scripts/geojson/maps/fetch_streets.sh

30 lines
828 B
Bash
Raw Normal View History

2020-04-17 17:36:06 +02:00
#!/bin/bash
# WARNING: This script is not yet production ready. The slightest error in the wikipage can throw it off. Handle with care.
json=`curl 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Maps:Streets'`
2020-04-26 17:22:44 +02:00
data=`echo "$json" | json_reformat | sed -e 's/\\\\n//g' -n -e 's/begin:mapdata\([^}]\+\)/\1/gp' | sed -e "s/|-|/}/g"`
2020-04-17 17:36:06 +02:00
echo "["
export IFS="}"
for entry in $data; do
2020-04-26 17:22:44 +02:00
name=`echo "$entry" | sed -n 's/\s*\([^|]\+\).*/\1/p' | sed 's/ $//'`
coord=`echo "$entry" | sed -n 's/.*||\s*\([^|]\+\).*/\1/p'`
2020-04-17 17:36:06 +02:00
if [[ "$name" != "" && "$coord" != "" ]]; then
echo "{ \"type\": \"Feature\",
\"geometry\": {
\"type\": \"LineString\",
\"coordinates\": [
$coord
]
},
\"properties\": {
\"name\": \"$name\"
}
},"
fi
done
export IFS=" "
2020-04-17 17:36:06 +02:00
echo "{}"
echo "]"