Guest User

mediawiki_monitor_openbox.sh

a guest
Nov 29th, 2010
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.90 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. page=$(curl -s "$1/index.php?title=Special:RecentChanges&limit=${2:-50}")
  6. wiki=$(echo "$page"|grep -E '<title>.*</title>'|sed 's|Recent changes - ||;s|<title>||;s|</title>||;s|^[ \t]*||g')
  7. recent=$(echo "$page"|awk 'BEGIN {x=0}
  8. {
  9. if ($0~"<ul class=\"special\">") {x=1}
  10. if (x==1) {print $0}
  11. if ($0~"<div class=\"printfooter\">") {x=0}
  12. }'|sed 's/<ul class="special">//g;s|<div class="printfooter">||;s|</ul>||g;/^$/d')
  13. echo "<openbox_pipe_menu>"
  14. echo "<item label=\"Visit $wiki\"><action label=\"Execute\"><command>${3:-firefox} $1</command></action></item>"
  15. echo "<item label=\"Check $wiki&apos;s uploads\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/upload</command></action></item>"
  16. echo "<item label=\"Check $wiki&apos;s blocks\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/block</command></action></item>"
  17. echo "<item label=\"Check $wiki&apos;s protections\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/protect</command></action></item>"
  18. echo "<item label=\"Check $wiki&apos;s new users\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/newusers</command></action></item>"
  19. echo "<item label=\"Check $wiki&apos;s patrols\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/patrol</command></action></item>"
  20. echo "<item label=\"Check $wiki&apos;s deletions\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/delete</command></action></item>"
  21. echo "<item label=\"Check $wiki&apos;s moves\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/move</command></action></item>"
  22. echo "<item label=\"Check $wiki&apos;s user renames\"><action label=\"Execute\"><command>${3:-firefox} $1/Special:Log/renameuser</command></action></item>"
  23. echo "<separator label=\"Article changes\" />"
  24. menu=$(echo "$recent"| while read line;
  25. do  
  26. diff=$(echo "$line"|grep -E 'diff=[0-9]+' -o|sed 's|diff=||')
  27. curid=$(echo "$line"|grep -E 'curid=[0-9]+' -m 1 -o|sed 's|curid=||'|head -n 1)
  28. oldid=$(echo "$line"|grep -E 'oldid=[0-9]+' -m 1 -o|sed 's|oldid=||')
  29. echo "$curid"
  30. if [ "$curid" != "" ];then
  31.     artc=$(echo "$line"|grep -E '  <a href=".*" title=".*">.*</a>‎;(?:&#32;| )?' -o)
  32.     time=$(echo "$line"|grep -E '[0-9]{2}:[0-9]{2}' -o)
  33.     title=$(echo "$artc"|grep -E '>.*</a>' -o|sed 's/>//g;s/<\/a//g')
  34.     link=$(echo "$artc"|grep -E 'href=".*"' -o|sed 's/href="//g;s/"//g;s/ title=.*//g;s|^/.*/||')
  35.     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)
  36.     id=$(echo "$title $time"|sed 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ /abcdefghijklmnopqrstuvwxyz-/;s/://g')
  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 "  <menu label=\"$time @ $title by $user $stats\" id=\"$id\">"
  42.     echo "      <item label=\"${comment:-"No comment on this change."}\" />"
  43.     echo "      <item label=\"Visit $title\"><action label=\"Execute\"><command>${3:-firefox} $1/index.php?title=$link</command></action></item>"
  44.     if [ "$diff" != "" ];then
  45.         echo "      <item label=\"Diff\"><action label=\"Execute\"><command>${3:-firefox} $1/index.php?title=page&amp;curid=$curid&amp;diff=$diff&amp;oldid=$oldid</command></action></item>"
  46.     fi
  47.     echo "      <item label=\"Hist\"><action label=\"Execute\"><command>${3:-firefox} $1/index.php?title=page&amp;curid=$curid&amp;action=history</command></action></item>"
  48.     echo "      <item label=\"$user&apos;s profile\"><action label=\"Execute\"><command>${3:-firefox} $1/index.php?title=User:${userurl:-$user}</command></action></item>"
  49.     echo "      <item label=\"$user&apos;s talk page\"><action label=\"Execute\"><command>${3:-firefox} $1/index.php?title=User_talk:${userurl:-$user}</command></action></item>"
  50.     echo "      <item label=\"$user&apos;s contributions\"><action label=\"Execute\"><command>${3:-firefox} $1/index.php?title=Special:Contributions/${userurl:-$user}</command></action></item>"
  51.     echo '  </menu>'
  52. fi
  53. done);
  54. if [ "$menu" == "" ];then
  55.     echo "<item label=\"There are no article changes to update\" />"
  56. else
  57.     echo "$menu"
  58. fi
  59.     echo "</openbox_pipe_menu>"
Advertisement
Add Comment
Please, Sign In to add comment