Guest User

mediawiki_monitor.sh

a guest
Nov 29th, 2010
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.77 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. #TODO: port to openbox
  6. #TODO: use favicon as icon
  7. #path to icon: $1/favicon.ico
  8. page=$(curl -s "$1/index.php?title=Special:RecentChanges&limit=${2:-50}")
  9. wiki=$(echo "$page"|grep -E '<title>.*</title>'|sed 's|Recent changes - ||;s|<title>||;s|</title>||;s|^[ \t]*||g')
  10. recent=$(echo "$page"|awk 'BEGIN {x=0}
  11. {
  12. if ($0~"<ul class=\"special\">") {x=1}
  13. if (x==1) {print $0}
  14. if ($0~"<div class=\"printfooter\">") {x=0}
  15. }'|sed 's/<ul class="special">//g;s|<div class="printfooter">||;s|</ul>||g;/^$/d')
  16. echo "<menu name=\"$wiki\">"
  17. echo "<item type=\"launcher\"><name>Visit $wiki</name><command>${3:-firefox} $1</command></item>"
  18. echo "<item type=\"launcher\"><name>Check $wiki&apos;s uploads</name><command>${3:-firefox} $1/Special:Log/upload</command></item>"
  19. echo "<item type=\"launcher\"><name>Check $wiki&apos;s blocks</name><command>${3:-firefox} $1/Special:Log/block</command></item>"
  20. echo "<item type=\"launcher\"><name>Check $wiki&apos;s protections</name><command>${3:-firefox} $1/Special:Log/protect</command></item>"
  21. echo "<item type=\"launcher\"><name>Check $wiki&apos;s new users</name><command>${3:-firefox} $1/Special:Log/newusers</command></item>"
  22. echo "<item type=\"launcher\"><name>Check $wiki&apos;s patrols</name><command>${3:-firefox} $1/Special:Log/patrol</command></item>"
  23. echo "<item type=\"launcher\"><name>Check $wiki&apos;s deletions</name><command>${3:-firefox} $1/Special:Log/delete</command></item>"
  24. echo "<item type=\"launcher\"><name>Check $wiki&apos;s moves</name><command>${3:-firefox} $1/Special:Log/move</command></item>"
  25. echo "<item type=\"launcher\"><name>Check $wiki&apos;s user renames</name><command>${3:-firefox} $1/Special:Log/renameuser</command></item>"
  26. echo "<separator name=\"Article changes\"/>"
  27. menu=$(echo "$recent"| while read line;
  28. do  
  29. diff=$(echo "$line"|grep -E 'diff=[0-9]+' -o|sed 's|diff=||')
  30. curid=$(echo "$line"|grep -E 'curid=[0-9]+' -m 1 -o|sed 's|curid=||'|head -n 1)
  31. oldid=$(echo "$line"|grep -E 'oldid=[0-9]+' -m 1 -o|sed 's|oldid=||')
  32. echo "$curid"
  33. if [ "$curid" != "" ];then
  34.     artc=$(echo "$line"|grep -E '  <a href=".*" title=".*">.*</a>‎;(?:&#32;| )?' -o)
  35.     time=$(echo "$line"|grep -E '[0-9]{2}:[0-9]{2}' -o)
  36.     title=$(echo "$artc"|grep -E '>.*</a>' -o|sed 's/>//g;s/<\/a//g')
  37.     link=$(echo "$artc"|grep -E 'href=".*"' -o|sed 's/href="//g;s/"//g;s/ title=.*//g;s|^/.*/||')
  38.     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)
  39.     statsuser=$(echo "$line"|grep -E '(pos|neg|null)'\''>\((\+|-)?[,0-9]+\)</.*>.*<a href=".*"( title=".*" class=".*"| class=".*" title=".*")>.*</a> <' -o)
  40.     stats=$(echo "$statsuser"|grep -E '(pos|neg|null)'\''>\((\+|-)?[,0-9]+\)<' -o|grep -E '>.*<' -o|sed 's/>//g;s/<//g')
  41.     user=$(echo "$statsuser"|grep -E '<a href=".*"( title=".*" class=".*"| class=".*" title=".*")>.*</a>' -o|grep -E '>.*<' -o|sed 's/>//g;s/<//g')
  42.     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=||')
  43.     echo "  <menu name=\"$time @ $title by $user $stats\">"
  44.     echo "      <item type=\"launcher\"><name>${comment:-"No comment on this change."}</name></item>"
  45.     echo "      <item type=\"launcher\"><name>Visit $title</name><command>${3:-firefox} $1/index.php?title=$link</command></item>"
  46.     if [ "$diff" != "" ];then
  47.         echo "      <item type=\"launcher\"><name>Diff</name><command>${3:-firefox} $1/index.php?title=page&amp;curid=$curid&amp;diff=$diff&amp;oldid=$oldid</command></item>"
  48.     fi
  49.     echo "      <item type=\"launcher\"><name>Hist</name><command>${3:-firefox} $1/index.php?title=page&amp;curid=$curid&amp;action=history</command></item>"
  50.     echo "      <item type=\"launcher\"><name>$user&apos;s profile</name><command>${3:-firefox} $1/index.php?title=User:${userurl:-$user}</command></item>"
  51.     echo "      <item type=\"launcher\"><name>$user&apos;s talk page</name><command>${3:-firefox} $1/index.php?title=User_talk:${userurl:-$user}</command></item>"
  52.     echo "      <item type=\"launcher\"><name>$user&apos;s contributions</name><command>${3:-firefox} $1/index.php?title=Special:Contributions/${userurl:-$user}</command></item>"
  53.     echo '  </menu>'
  54. fi
  55. done);
  56. if [ "$menu" == "" ];then
  57.     echo "<item type=\"launcher\"><name>There are no article changes to update</name></item>"
  58. else
  59.     echo "$menu"
  60. fi
  61.     echo "</menu>"
  62. #sed 's|&|&amp;|g;s|'\''|&apos;|g;s|<|&lt;|g;s|>|&gt;|g;s|\"|&quot;|g' ?
  63. #talk: $1/User_talk:<user>
  64. #contrib: $1/Special:Contributions/<user>
  65. #profile: $1/User:<user>
  66. #
  67. #page:
  68. #$1/index.php?title=page&amp;curid=$curid&amp;action=history
  69. #$1/index.php?title=page&amp;curid=$curid&amp;diff=$diff&amp;oldid=$oldid
  70. #$1/index.php?title=User:$userurl
  71. #$1/index.php?title=User_talk:$userurl
  72. #$1/index.php?title=Special:Contributions/$userurl
  73.  
  74. #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)
  75. #statsuser=$(echo "$line"|grep -E '(pos|neg|null)'\''>\((\+|-)?[,0-9]+\)</.*>.*<a href=".*"( title=".*" class=".*"| class=".*" title=".*")>.*</a> <' -o)
  76. #stats=$(echo "$statsuser"|grep -E '(pos|neg|null)'\''>\((\+|-)?[,0-9]+\)<' -o|grep -E '>.*<' -o|sed 's/>//g;s/<//g')
  77. #user=$(echo "$statsuser"|grep -E '<a href=".*"( title=".*" class=".*"| class=".*" title=".*")>.*</a>' -o|grep -E '>.*<' -o|sed 's/>//g;s/<//g')
Advertisement
Add Comment
Please, Sign In to add comment