#!/bin/sh
# egy lap hivatkozasait lekerdezo script. Parameter: a szocikk cime. Eredmeny: ./eredm.wget

URL="https://hu.wikipedia.org/w/api.php?action=query&prop=revisions&generator=backlinks&gblredirect=&gbltitle=$1&format=xml&gbllimit=max"
#URL="https://hu.wikipedia.org/w/api.php?action=query&prop=revisions&generator=backlinks&gblredirect=&gbltitle=Wikipédia:Kocsmafal_(műszaki)&format=xml&gbllimit=max"
#URL="http://localhost/proba/api.php?action=query&prop=revisions&generator=backlinks&gblredirect=&gbltitle=Kategória:Lilypond&format=xml&gbllimit=4"
unset FOLYT
MUNKA=ins.ins
EREDM=eredm.wget
rm -f $EREDM
while true
do	#echo >>$EREDM
	#echo =========== f = $f ============   >>$EREDM
	wget "$URL$FOLYT" -O - 2>/dev/null | sed -e 's/<page/\n&/g' -e 's/<continue /\n&/g' >$MUNKA
	FOLYT=`grep '<continue ' $MUNKA | logcut -f /gblcontinue=/ | logcut -d \" -f 2`
	echo "$FOLYT"
	grep '^<page ' $MUNKA >>$EREDM
	if [ -z "$FOLYT" ] ; then echo kilepek ; break ; fi
	FOLYT="&gblcontinue=$FOLYT"
done
rm -f $MUNKA
