Guest User

mediawiki_monitor_pekwm.sh

a guest
Nov 29th, 2010
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.14 KB | None | 0 0
  1. #!/bin/sh
  2. #TODO: Fix for wikipedia
  3. #regex idea so far:
  4. #$mainurl=$(echo $1|grep 'http://[^/]*' -o)
  5. #not sure if you can have empty action items
  6. page=$(curl -s "$1/index.php?title=Special:RecentChanges&limit=${2:-50}")
  7. wiki=$(echo "$page"|grep -E '<title>.*</title>'|sed 's|Recent changes - ||;s|<title>||;s|</title>||;s|^[ \t]*||g')
  8. recent=$(echo "$page"|awk 'BEGIN {x=0}
  9. {
  10. if ($0~"<ul class=\"special\">") {x=1}
  11. if (x==1) {print $0}
  12. if ($0~"<div class=\"printfooter\">") {x=0}
  13. }'|sed 's/<ul class="special">//g;s|<div class="printfooter">||;s|</ul>||g;/^$/d')
  14. echo "Dynamic {"
  15. echo "Entry = \"Visit $wiki\" { Actions = \"Exec ${3:-firefox} $1 &\" }"
  16. echo "Entry = \"Check $wiki's uploads\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/upload &\" }"
  17. echo "Entry = \"Check $wiki's blocks\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/block &\" }"
  18. echo "Entry = \"Check $wiki's protections\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/protect &\" }"
  19. echo "Entry = \"Check $wiki's new users\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/newusers &\" }"
  20. echo "Entry = \"Check $wiki's patrols\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/patrol &\" }"
  21. echo "Entry = \"Check $wiki's deletions\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/delete &\" }"
  22. echo "Entry = \"Check $wiki's moves\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/move &\" }"
  23. echo "Entry = \"Check $wiki's user renames\" { Actions = \"Exec ${3:-firefox} $1/Special:Log/renameuser &\" }"
  24. echo "Separator {}"
  25. menu=$(echo "$recent"| while read line;
  26. do  
  27. diff=$(echo "$line"|grep -E 'diff=[0-9]+' -o|sed 's|diff=||')
  28. curid=$(echo "$line"|grep -E 'curid=[0-9]+' -m 1 -o|sed 's|curid=||'|head -n 1)
  29. oldid=$(echo "$line"|grep -E 'oldid=[0-9]+' -m 1 -o|sed 's|oldid=||')
  30. echo "$curid"
  31. if [ "$curid" != "" ];then
  32.     artc=$(echo "$line"|grep -E '  <a href=".*" title=".*">.*</a>‎;(?:&#32;| )?' -o)
  33.     time=$(echo "$line"|grep -E '[0-9]{2}:[0-9]{2}' -o)
  34.     title=$(echo "$artc"|grep -E '>.*</a>' -o|sed 's/>//g;s/<\/a//g')
  35.     link=$(echo "$artc"|grep -E 'href=".*"' -o|sed 's/href="//g;s/"//g;s/ title=.*//g;s|^/.*/||')
  36.     comment=$(echo "$line"|grep -E '<span class="comment">\(.*\)</span>' -o|sed 's/<\/span>//g;s/<span class="comment">//g;s/<span class="autocomment">//g;s/<a href=".*" title=".*">→<\/a>/→ /g;s/&#32\;//g;s|<|\&lt\;|g;s|>|\&gt\;|g'|head -c 30)
  37.     statsuser=$(echo "$line"|grep -E '(pos|neg|null)'\''>\((\+|-)?[,0-9]+\)</.*>.*<a href=".*"( title=".*" class=".*"| class=".*" title=".*")>.*</a> <' -o)
  38.     stats=$(echo "$statsuser"|grep -E '(pos|neg|null)'\''>\((\+|-)?[,0-9]+\)<' -o|grep -E '>.*<' -o|sed 's/>//g;s/<//g')
  39.     user=$(echo "$statsuser"|grep -E '<a href=".*"( title=".*" class=".*"| class=".*" title=".*")>.*</a>' -o|grep -E '>.*<' -o|sed 's/>//g;s/<//g')
  40.     userurl=$(echo "$statsuser"|grep -E 'href=".*/(index.php\?title=)?User:.*(&amp;.*)?"( title| class)' -o|sed 's/href="//g;s/"//g;s/ title=.* class//g;s/ class=.* title//g'|grep -E '(index.php\?title=|/)?User:.*(&amp;action.*)?' -o|sed 's/User://g;s/index.php\?title=//g;s/\///g;s/&amp;action.*//g;s/ title=.* class//g;s/ class=.* title//g;s|^index.php?title=||')
  41.     echo "  Submenu = \"$time @ $title by $user $stats\" {"
  42.     echo "      Entry = \"${comment:-"No comment on this change."}\" {}"
  43.     echo "      Entry = \"Visit $title\" { Actions = \"Exec ${3:-firefox} $1/index.php?title=$link &\" }"
  44.     if [ "$diff" != "" ];then
  45.         echo "      Entry = \"Diff\" { Actions = \"Exec ${3:-firefox} $1/index.php?title=page&amp;curid=$curid&amp;diff=$diff&amp;oldid=$oldid &\" }"
  46.     fi
  47.     echo "      Entry = \"Hist\" { Actions = \"Exec ${3:-firefox} $1/index.php?title=page&amp;curid=$curid&amp;action=history &\" }"
  48.     echo "      Entry = \"$user&apos;s profile\" { Actions = \"Exec ${3:-firefox} $1/index.php?title=User:${userurl:-$user} &\" }"
  49.     echo "      Entry = \"$user&apos;s talk page\" { Actions = \"Exec ${3:-firefox} $1/index.php?title=User_talk:${userurl:-$user} &\" }"
  50.     echo "      Entry = \"$user&apos;s contributions\" { Actions = \"Exec ${3:-firefox} $1/index.php?title=Special:Contributions/${userurl:-$user} &\" }"
  51.     echo '  }'
  52. fi
  53. done);
  54. if [ "$menu" == "" ];then
  55.     echo "Entry = \"There are no article changes to update\" {}"
  56. else
  57.     echo "$menu"
  58. fi
  59.     echo "}"
Advertisement
Add Comment
Please, Sign In to add comment