diff options
author | Markus Koch <markus@notsyncing.net> | 2020-04-27 17:37:12 +0200 |
---|---|---|
committer | Markus Koch <markus@notsyncing.net> | 2020-04-27 17:38:19 +0200 |
commit | 05238dc5aec332970a082b84d174240c4262e95d (patch) | |
tree | e1afc96079cad81c4a8dd75eb01cec7a1eadd137 /scripts/geojson/fetch_all_points.sh | |
parent | c7c4975a571d1974d3807755a064d8489b60ffa4 (diff) | |
download | lifomapserver-05238dc5aec332970a082b84d174240c4262e95d.tar.gz lifomapserver-05238dc5aec332970a082b84d174240c4262e95d.tar.bz2 lifomapserver-05238dc5aec332970a082b84d174240c4262e95d.zip |
Add categories for markers
This commit obsoletes the many fetch scripts and combines them
into a single script, creating a single json, but with category
information.
Diffstat (limited to 'scripts/geojson/fetch_all_points.sh')
-rwxr-xr-x | scripts/geojson/fetch_all_points.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/scripts/geojson/fetch_all_points.sh b/scripts/geojson/fetch_all_points.sh new file mode 100755 index 0000000..81c46e0 --- /dev/null +++ b/scripts/geojson/fetch_all_points.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +json=`curl -s 'https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&list=search&redirects=1&converttitles=1&srsearch=%7B%7BCo%7C&srlimit=max&srwhat=text&srprop=snippet'` +data=`echo "$json" | json_reformat`; + +echo "["; + +IFS=$'\n'; +for line in $data; do + temp=`echo "$line" | sed -n 's/^\s*{\s*$/END/p'` + if [[ "$temp" == "END" ]]; then + title=""; + coords=""; + fi + temp=`echo "$line" | sed -n 's/\s*"title": "*\([^"]\+\).*/\1/p'` + if [[ "$temp" != "" ]]; then + title="$temp"; + fi + temp=`echo "$line" | sed -n 's#.*<span class=.searchmatch.>Co<\/span>|\([0-9\-]\+\)|\([0-9\-]\+\)|\([0-9\-]\+\).*#\1,\3#p'` + if [[ "$temp" != "" ]]; then + coords="$temp"; + fi + if [[ "$title" != "" && "$coords" != "" ]]; then + echo "{\"type\": \"Feature\", \"properties\": {\"name\": \"$title\"," + echo -n "\"categories\": [" + urltitle=`echo "$title" | sed 's/ /%20/g'` + cjson=`curl -s "https://wiki.linux-forks.de/mediawiki/api.php?action=query&format=json&titles=$urltitle&prop=categories" | json_reformat -m` + categories=`echo "$cjson" | sed -n 's/.*\("categories":[^]]\+\).*/\1/p'`; + IFS='}' + fc="true"; + for entry in $categories; do + if [[ "$fc" != "true" ]]; then + echo -n ","; + fi + category=`echo "$entry" | sed -n 's/.*Category:\([^"]\+\).*/\1/p'` + echo -n "\"$category\""; + fc="false"; + done; + IFS=$'\n' + echo "]},"; + echo "\"geometry\": {\"type\": \"Point\", \"coordinates\": [$coords]}},"; + title=""; + coords=""; + fi +done +IFS=" "; + +echo "{}]"; |