summaryrefslogtreecommitdiff
path: root/scripts/geojson/fetch_all_points.sh
blob: 81c46e0018435e45d3651233cdd4b598452bfe83 (plain)
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
#!/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 "{}]";