Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo
- echo \(C\) 2013 Artur \"Mrowqa\" Jamro ----- http://mrowqa.pl/
- echo Tool for auto-checking whether GCI task has reviewed.
- echo Version 1.17.2
- echo
- ########################################################
- function getState() { # params: $task_id
- local task_id=$1
- result=$(wget -qO- http://www.google-melange.com/gci/task/view/google/$CONTEST_YEAR/$task_id 2> /dev/null | grep Status: | sed -r s/^.*\"emph\"\>//g | sed -r s/\<.*$//g)
- echo $result
- }
- function onStateChange() { # params: $newState, $prevState
- local newState=$1
- local prevState=$2
- echo
- echo Task changed state!
- echo New state: $newState
- # notifyViaToast # you probably don't have "toast" command, so beeping is still default; i'll maybe upload this binary :)
- notifyBeeping # you can choose these functions you want, you can even write some yourself :)
- }
- ########################################################
- ####### notify functions - you can choose these you want or even write some yourself :)
- function notifyBeeping () {
- echo Press Ctrl-C to stop beeping.
- break_on_ctrl_c=0
- while [ "$ctrl_c_pressed" == "0" ]; do
- echo -en "\007" # beep
- sleep 1s
- done
- ctrl_c_pressed=0
- break_on_ctrl_c=1
- }
- function notifyViaLibnotify () { # Dedicated for GNOME Shell, will work partly on Unity and Xfce, also probably KDE and other DEs with libnotify support
- # thanks to: Mateusz "m4tx" Maćkowski --- http://m4tx.pl
- notify-send --expire-time=3600000 --urgency=critical 'GCI2013' "Task $task_id: $taskState! \nhttp://www.google-melange.com/gci/task/view/google/$CONTEST_YEAR/$task_id$@"
- }
- function notifyViaToast () { #win8+
- local toastState=Timeout
- local imageFile=$(pwd)/gci2013-logo.png
- while [ "$toastState" == "Timeout" ]; do
- toastState=$(toast -t "Task ID: $task_id" -p $imageFile -m "New task state: $taskState!
- Click here to see your task." -w)
- done
- if [ "$toastState" == "Activated" ]; then
- explorer http://www.google-melange.com/gci/task/view/google/$CONTEST_YEAR/$task_id
- fi
- }
- # tried write one notify function for win8 and message box, but still had problems with bash...
- ########################################################
- break_on_ctrl_c=1
- ctrl_c_pressed=0
- control_c() { # run if user hits control-c
- ctrl_c_pressed=1
- if [ "$break_on_ctrl_c" == "1" ]; then
- echo Ctr-C interruption! Exiting...
- exit
- fi
- }
- # trap keyboard interrupt (control-c)
- trap control_c SIGINT
- ########################################################
- ########################################################
- if [ -z "$1" ]; then
- echo Usage: wait_for_task \<task_id\>
- echo Usage: wait_for_task -
- echo
- echo If you choose second version, \<task_id\> will be read from "task.id" file.
- exit
- fi
- task_id=$1
- TIMESTAMP=60s
- CONTEST_YEAR=gci2013 # will probably works for GSoC too
- if [ "$task_id" == "-" ]; then
- task_id=$(cat task.id)
- fi
- echo Waiting for task state changes, task: $task_id
- echo Checking every $TIMESTAMP
- prevState=$(getState $task_id)
- if [ "$prevState" == "Closed" ]; then
- echo Task $task_id is closed!
- exit
- fi
- echo Current state: $prevState
- echo
- while [ "true" ]; do
- taskState=$(getState $task_id)
- if [ "$taskState" != "$prevState" ]; then
- onStateChange $taskState $prevState # wait for user interaction, don't check firstly once more state
- if [ "$taskState" == "Closed" ]; then
- break
- fi
- echo
- echo Still waiting for state changes...
- fi
- prevState=$taskState
- sleep $TIMESTAMP
- done
- echo
- echo Task $task_id closed!
Advertisement
Add Comment
Please, Sign In to add comment