summaryrefslogtreecommitdiff
path: root/scripts/geojson/get_rendered_meta.sh
blob: 9debc537e4bec6467bb798809d3245c9901eb754 (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
49
#!/bin/bash

BASE="https://wiki.linux-forks.de"

mode="find_description"

thumbnail=""
categories=""

data=`curl -s "$1"`

temp=`echo "$data" | sed -n 's/<p>\(.\+\).*/\1/p' | grep -v -e '^<br />$' | sed 's#^</p>##' | head -n1`
if [ "$temp" != "" ]; then
	temp=`echo "$temp" | sed "s#href=\"#href=\"$BASE#g" | sed 's/"/\\\\"/g' | sed 's/\t//g'`
	description="$temp"
	mode="find_infobox";
fi

IFS=$'>';
for line in $data; do
	if [ "$mode" == "find_infobox" ]; then
		if [ "`echo \"$line\" | grep 'infobox'`" != "" ]; then
			mode="image";
		fi
	elif [ "$mode" == "image" ]; then
		temp=`echo "$line" | sed -n 's/.*img.*src="\([^"]\+\).*/\1/p'`;
		if [ "$temp" != "" ]; then
			thumbnail="$BASE$temp"
			mode="find_cat"
		fi
	elif [ "$mode" == "find_cat" ]; then
		if [ "`echo \"$line\" | grep 'mw-normal-catlinks'`" != "" ]; then
			mode="cat";
		fi
	elif [ "$mode" == "cat" ]; then
		temp=`echo "$line" | sed -n 's/.*title="Category:\([^"]\+\).*/\1/pg' | grep -v 'page does not exist'`
		if [ "$temp" != "" ]; then
			if [ "$categories" != "" ]; then
				categories="$categories,"
			fi
			categories="$categories\"$temp\""
		fi
	fi
done
IFS=" ";

echo "\"categories\": [$categories],"
echo "\"image\": \"$thumbnail\","
echo "\"description\": \"$description\""