Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Сумма оценок пользователя в сообщениях форума на сайте skisport.ru
- user_id=975 # номер пользователя
- if [ -n "$1" ]
- then
- user_id="$1"
- fi
- user_page='https://www.skisport.ru/people/forum/'$user_id'/'
- rating_plus=0
- rating_minus=0
- pagesN=1
- res=`curl -s $user_page | grep 'последняя'` # поиск ссылки на последнюю страницу комментариев
- comments=`echo $res`
- if [ -n "$res" ]
- then
- prefix='<li><a href="/people/forum/'$user_id'/?PAGEN_1=' # текст ссылки до номера на последнюю страницу
- suffix='">последняя</a></li>'
- pagesN=${comments#$prefix}
- pagesN=${pagesN//$suffix/''} # количество страниц ссылок на комментарии пользователя
- fi
- for (( indx=1; indx<=$pagesN; indx++ ))
- do
- page_url=$user_page'?PAGEN_1='$indx
- comment_links=`curl -s $page_url | grep 'href="[a-zA-Z0-9/-]*/#[0-9]*"'`
- for comment in $comment_links
- do
- pos=`expr index "$comment" \"` # начало относительной ссылки, выкидываем <a href="
- if [ $pos -eq 0 ]
- then
- continue
- fi
- comment_url='https://www.skisport.ru'${comment:$pos} # абcолютная ссылка на коммент
- comment_url=${comment_url//'"'/''}
- #echo $comment_url
- pos2=`expr index "$comment_url" \#`
- comment_id=${comment_url:$pos2} # id комментария (номер в конце ссылки после решетки)
- votes=`curl -s $comment_url | grep -A3 "[a-zA-Z-]*$comment_id[0-9-]*result" | grep "олосов"`
- if echo "$votes" | grep "нет голосов" > /dev/null
- then
- echo $comment_url' 0 0'
- continue
- fi
- votes_plus=`echo $votes | awk -F" " '{print $6}'`
- votes_minus=`echo $votes | awk -F" " '{print $9}'`
- rating_plus=$(expr $rating_plus + $votes_plus)
- rating_minus=$(expr $rating_minus + $votes_minus)
- echo $comment_url' '$votes_plus $votes_minus '( ' $rating_plus $rating_minus ')'
- done
- done
- rating=$(expr $rating_plus - $rating_minus)
- echo 'рейтинг пользователя '$user_id' по сообщениям форума = '$rating' (+'$rating_plus' -'$rating_minus')'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement