summaryrefslogtreecommitdiff
path: root/scripts/geojson/fetch_single.sh
blob: 61ab79d5cbae6cfadcd1fd2c39d819b7d4e779e2 (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
#!/bin/bash

json=`curl "https://wiki.linux-forks.de/mediawiki/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=$1&rvsection=0&rvslots=main" | sed -s "s/\\\\\\\\n//g"`

title=`echo $json | sed -n 's/.*"title":\s*"\([^"]\+\).*/\1/p'`
image=`echo "$json" | sed -n "s/.*image = \([^|]*\).*/\1/p"`

coords=`echo "$json" | sed -n "s/.*coordinates = {{Co|\([^}]*\).*/\1/p"`
coord_x=`echo "$coords" | sed -n "s/\([^|]\+\).*/\1/p"`
coord_y=`echo "$coords" | sed -n "s/.*|\([^|]\+\).*/\1/p"`

description=`echo $json | sed -n "s/.*coordinates.*[^']*'''\([^']*\)'''\([^\.]*\).*/\1\2./p"
`

if [[ "$coord_x" != "" && "$coord_y" != "" ]]; then
	echo "{\
		\"type\": \"Feature\",\
		\"properties\": {\
		\"name\": \"$title\",\
		\"amenity\": \"City\",\
		\"description\": \"$description\",\
		\"image\": \"https://wiki.linux-forks.de/mediawiki/images/thumb/0/0e/$image/250px-$image\"\
		},\
		\"geometry\": {\
		\"type\": \"Point\",\
		\"coordinates\": [$coord_x, $coord_y]\
		}\
	},"
fi