Script 'schedule' was completely re-written.
This commit is contained in:
parent
474bd0a1c2
commit
9f872ee6eb
129
schedule
129
schedule
@ -1,48 +1,125 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
repo=fat0troll/lorchess
|
REPO=fat0troll/lorchess
|
||||||
tournament=autumn2013
|
TOURNEY=autumn2013
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
digit='[[:digit:]]\+'
|
date="[0-9]\{2\}\.[0-9]\{2\}\.[0-9]\{4\}"
|
||||||
|
result="\(0\|1\|0\.5\):\(0\|1\|0\.5\)"
|
||||||
|
|
||||||
# Colors
|
# Colors
|
||||||
cyan='\\033[01;36m'
|
restore="\033[00m"
|
||||||
red='\\033[01;31m'
|
red="\033[01;31m"
|
||||||
restore='\\033[00m'
|
green="\033[01;32m"
|
||||||
|
yellow="\033[01;33m"
|
||||||
|
cyan="\033[01;36m"
|
||||||
|
|
||||||
# Note that we use `"$@"' to let each command-line parameter expand to a
|
# Highlight output
|
||||||
# separate word. The quotes around `$@' are essential!
|
highlight () {
|
||||||
# We need ARGS as the `eval set --' would nuke the return value of getopt.
|
line=$1
|
||||||
args=$(getopt --options p: --longoptions player: -- "$@")
|
|
||||||
|
|
||||||
# Note the quotes around `$ARGS': they are essential!
|
# Highlight the tour heading
|
||||||
eval set -- "$args"
|
line=$(sed "s/Тур/\\${green}\0\\${restore}/g" <<< "$line")
|
||||||
|
line=$(sed "s/№[0-9]\+/\\${cyan}\0\\${restore}/g" <<< "$line")
|
||||||
|
line=$(sed "s/^=*$/\\${green}\0\\${restore}/g" <<< "$line")
|
||||||
|
|
||||||
|
# Highlight the tour duration
|
||||||
|
line=$(sed "s/\(^.*\):/\\${green}\1\\${restore}:/g" <<< "$line")
|
||||||
|
|
||||||
|
# Highlight date
|
||||||
|
line=$(sed "s/${date}/\\${cyan}\0\\${restore}/g" <<< "$line")
|
||||||
|
|
||||||
|
echo -e "$line"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Note that we use '"$@"' to let each command-line parameter expand to a
|
||||||
|
# separate word. The quotes around '$@' are essential!
|
||||||
|
# We need 'opts' as the 'eval set --' would nuke the return value of getopt
|
||||||
|
opts=$(getopt --options p: --longoptions player: -- "$@")
|
||||||
|
|
||||||
|
# Note the quotes around '$opts': they are essential!
|
||||||
|
eval set -- "$opts"
|
||||||
|
|
||||||
|
name=""
|
||||||
if [[ $1 == -p || $1 == --player ]]; then
|
if [[ $1 == -p || $1 == --player ]]; then
|
||||||
name=$2
|
name=$2
|
||||||
shift 2
|
shift 2
|
||||||
fi
|
fi
|
||||||
shift
|
shift
|
||||||
|
|
||||||
for tour in $@; do
|
# Generate the sequence of tours to search in
|
||||||
# Change tour numbers: `1' -> `01', `2' -> `02', and so on
|
if [[ -z "$@" ]]; then
|
||||||
tour=0"$tour"
|
tours=$(seq -f "%02g" 1 99)
|
||||||
tour=${tour:(-2)}
|
else
|
||||||
|
# Change tour numbers: '1' -> '01', '2' -> '02', and so on
|
||||||
|
tours=$(for tour in "$@"; do printf "%02g " $tour; done)
|
||||||
|
fi
|
||||||
|
|
||||||
url=https://raw.github.com/$repo/master/$tournament/tour_$tour/tour_info
|
for tour in $tours; do
|
||||||
|
|
||||||
echo ">>>"
|
# Store 'tour_info' in an array of lines
|
||||||
curl -q --silent -w '\n' $url | while read line; do
|
url=https://raw.github.com/$REPO/master/$TOURNEY/tour_$tour/tour_info
|
||||||
if [[ -z $line ]]; then
|
lines=()
|
||||||
echo
|
while read line; do
|
||||||
elif [[ -z $name || $(egrep "Тур|=|Время|$name" <<< "$line") ]]; then
|
lines+=("$line")
|
||||||
# Colorize output
|
done <<< "$(curl --fail -q --silent --write-out '\n' $url)"
|
||||||
line=$(sed "s/${digit}/${cyan}\0${restore}/g" <<< "$line")
|
|
||||||
[[ -n $name ]] && line=$(sed "s/${name}/${red}\0${restore}/g" <<< "$line")
|
# Produce output only if 'tour_info' exists
|
||||||
echo -e $line
|
if [[ -n $lines ]]; then
|
||||||
|
|
||||||
|
# Decide to skip the tour or not
|
||||||
|
unskip=""; player=""
|
||||||
|
for ((i=5; i<${#lines[@]}; ++i)); do
|
||||||
|
line="${lines[$i]}"
|
||||||
|
|
||||||
|
# Don't skip if an unfinished game exists
|
||||||
|
if [[ -z $(grep "$result" <<< "$line") ]]; then
|
||||||
|
if [[ -z "$name" ]]; then
|
||||||
|
unskip="yes"
|
||||||
|
|
||||||
|
# In addition, if the player was passed as an
|
||||||
|
# argument, check if this is his game or not
|
||||||
|
elif [[ -n $(grep -o "[^ ]*${name}[^ ]*" <<< "$line") ]]; then
|
||||||
|
unskip="yes"
|
||||||
|
# Complete player's name
|
||||||
|
player=$(grep -o "[^ ]*${name}[^ ]*" <<< "$line")
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ -n "$unskip" ]]; then
|
||||||
|
|
||||||
|
# The separator between tours
|
||||||
|
echo -en "$yellow"
|
||||||
|
for i in {1..41}; do echo -n "-"; done
|
||||||
|
echo -e "$restore"
|
||||||
|
|
||||||
|
# Output the tour heading as is
|
||||||
|
for ((i=0; i<5; ++i)); do highlight "${lines[$i]}"; done
|
||||||
|
|
||||||
|
# Lines with game info
|
||||||
|
for ((i=5; i<${#lines[@]}; ++i)); do
|
||||||
|
line="${lines[$i]}"
|
||||||
|
|
||||||
|
# Output only unfinished games
|
||||||
|
if [[ -z $(grep "$result" <<< "$line") ]]; then
|
||||||
|
if [[ -z "$player" ]]; then
|
||||||
|
highlight "$line"
|
||||||
|
|
||||||
|
# If the player was passed as an argument,
|
||||||
|
# highlight his name
|
||||||
|
elif [[ -n $(grep -o "${player}" <<< "$line") ]]; then
|
||||||
|
line=$(sed "s/${player}/\\${red}\0\\${restore}/g" <<< "$line")
|
||||||
|
highlight "$line"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# If the tour numbers were not passed as arguments, exit once
|
||||||
|
# the first non-existing 'tour_info' is reached
|
||||||
|
[[ -z "$@" ]] && break
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user