2020-04-30 18:29:53 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
BASE="https://wiki.linux-forks.de"
|
|
|
|
|
|
|
|
mode="find_description"
|
|
|
|
|
|
|
|
thumbnail=""
|
|
|
|
categories=""
|
|
|
|
|
|
|
|
data=`curl -s "$1"`
|
|
|
|
|
2021-02-09 22:19:04 +01:00
|
|
|
temp=`echo "$data" | sed -n 's/<p>\(.\+\).*/\1/p' | grep -v -e '^<br />$' | sed 's#^</p>##' | head -n1`
|
2020-04-30 18:29:53 +02:00
|
|
|
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\""
|