Script 'schedule': take into account the date of tour.
This commit is contained in:
parent
2a6f4fdbe9
commit
c7dff3cc27
102
schedule
102
schedule
@ -3,13 +3,13 @@
|
||||
# Distributed under the terms of the GNU General Public License v2
|
||||
|
||||
# REPO_DIR="https://github.com/fat0troll/lorchess"
|
||||
REPO_DIR=`dirname "$0"`
|
||||
REPO_DIR=
|
||||
|
||||
# Specify the tournament here
|
||||
TOURNAMENT=
|
||||
|
||||
# Version information
|
||||
VERSION="0.5"
|
||||
VERSION="0.6"
|
||||
|
||||
argv0=${0##*/}
|
||||
|
||||
@ -18,23 +18,24 @@ function usage {
|
||||
List games on tours of tournament
|
||||
|
||||
Usage: $argv0 [options] [tours]
|
||||
Tournament tours are restricted to sequence \`tours' given in
|
||||
Bash-style syntax, i.e., \`tours' may include explicit numbers
|
||||
(tours=1 3), intervals (tours={1..5}), or any combination of them.
|
||||
If no tours are specified, display each tour until an empty
|
||||
\`tour_info' is found. By default, only unaccomplished games are
|
||||
listed.
|
||||
Put the script under the root directory of your repository or set
|
||||
inner variable REPO_DIR to point to your local or remote GitHub
|
||||
repository. If the tournament is not the last one (default), store
|
||||
its sub-directory in inner variable TOURNAMENT.
|
||||
|
||||
Inner variable REPO points to the root of repository; its default
|
||||
value of \`dirname \$0\` can be replaced by a URL link, absolute or
|
||||
relative path. Inner variable TOURNAMENT specifies the sub-directory
|
||||
of tournament.
|
||||
Tournament tours are restricted to sequence 'tours' given in the
|
||||
Bash-style syntax, i.e., 'tours' may include explicit numbers
|
||||
(tours=1 3), intervals (tours={1..5}), or any combination of them.
|
||||
If no tours are specified, display all started tours (use '-f' to
|
||||
see future tours too). By default, only unaccomplished games are
|
||||
listed.
|
||||
|
||||
Options:
|
||||
-a List accomplished games too
|
||||
-f Allow to display future tours
|
||||
-p PLAYER Show game if PLAYER is a part of a player's name
|
||||
-f FORMAT Specify the output format; FORMAT is \`term'
|
||||
(default), \`html', or \`lor'
|
||||
-o FORMAT Specify the output format; FORMAT is 'term' (default),
|
||||
'html', or 'lor'
|
||||
-l Add the URL link to game (if accomplished)
|
||||
-h Show this help output
|
||||
-v Show version information
|
||||
@ -48,6 +49,7 @@ function version {
|
||||
}
|
||||
|
||||
function setup_repo {
|
||||
[[ -z $REPO_DIR ]] && REPO_DIR=`dirname "$0"`
|
||||
CURL_OPTS="-q --fail --location --silent"
|
||||
|
||||
# If no tournament given, set it to the last one
|
||||
@ -70,7 +72,7 @@ function setup_repo {
|
||||
TOURNAMENT=${TOURNAMENT%/}
|
||||
|
||||
# Convert REPO_DIR to an absolute path
|
||||
[[ $REPO_DIR =~ ^/ ]] || REPO_DIR=$(cd $REPO_DIR; pwd)
|
||||
[[ ! $REPO_DIR =~ ^/ ]] && REPO_DIR=$(cd $REPO_DIR; pwd)
|
||||
|
||||
REPO_URL="file://${REPO_DIR}"
|
||||
fi
|
||||
@ -90,6 +92,9 @@ function show_tour_sequence {
|
||||
tour_seq=$(ls -1 -d ${REPO_DIR}/${TOURNAMENT}/tours/[0-9][0-9]/ \
|
||||
| sed -E "s|${REPO_DIR}/${TOURNAMENT}/tours/([0-9]{2})/|\1|")
|
||||
fi
|
||||
else
|
||||
# Don't care about the begging of an explicitly specified tour
|
||||
SHOW_FUTURE=true
|
||||
fi
|
||||
|
||||
for tour in $tour_seq; do
|
||||
@ -108,27 +113,16 @@ function show_tour_sequence {
|
||||
function output_tour_info {
|
||||
local date_re="([0-9?]{2})\.([0-9?]{2})\.([0-9?]{4})"
|
||||
local res_re="(1-0|1/2|0-1)"
|
||||
local tour_num= date_beg= date_end=
|
||||
local white= black= result= game_date=
|
||||
# Lines with game info
|
||||
local output_lines=
|
||||
|
||||
while read line; do
|
||||
# Read 'tour_num'
|
||||
if [[ -z $tour_num ]]; then
|
||||
[[ $line =~ ^"Тур №"([0-9]+) ]] && local tour_num=${BASH_REMATCH[1]}
|
||||
continue
|
||||
fi
|
||||
|
||||
# Read 'date_beg' and 'date_end'
|
||||
if [[ -z $date_beg || -z $date_end ]]; then
|
||||
if [[ $line =~ ^"Время проведения:"\ +$date_re\ +-\ +$date_re ]]; then
|
||||
# Use short dates
|
||||
local date_beg=${BASH_REMATCH[1]}.${BASH_REMATCH[2]}
|
||||
local date_end=${BASH_REMATCH[4]}.${BASH_REMATCH[5]}
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
|
||||
# Read the number of tour
|
||||
get_tour_num
|
||||
# Read the begging and end of tour
|
||||
get_tour_dates
|
||||
# Keep game info if needed, and store it in variables 'white',
|
||||
# 'black', 'result', and 'game_date'
|
||||
if keep_game_info; then
|
||||
@ -141,7 +135,36 @@ function output_tour_info {
|
||||
fi
|
||||
done <<< "$tour_info"
|
||||
|
||||
[[ -n $output_lines ]] && eval "info_output_$FORMAT"
|
||||
[[ -n $output_lines ]] && eval info_output_$FORMAT
|
||||
}
|
||||
|
||||
function get_tour_num {
|
||||
if [[ -z $tour_num ]]; then
|
||||
[[ $line =~ ^"Тур №"([0-9]+) ]] && tour_num=${BASH_REMATCH[1]}
|
||||
continue
|
||||
fi
|
||||
}
|
||||
|
||||
function get_tour_dates {
|
||||
if [[ -z $date_beg || -z $date_end ]]; then
|
||||
if [[ $line =~ ^"Время проведения:"\ +($date_re)\ +-\ +($date_re) ]]; then
|
||||
date_beg=${BASH_REMATCH[1]} date_end=${BASH_REMATCH[5]}
|
||||
|
||||
if ! $SHOW_FUTURE; then
|
||||
# Unknown beginning of tour
|
||||
[[ $date_beg =~ \? ]] && break
|
||||
|
||||
# The date of tour later than today
|
||||
local date_tour=$(sed -E "s/${date_re}/\3-\2-\1/" <<< $date_beg)
|
||||
local date_unix=$(date -d $date_tour +%s) this_unix=$(date +%s)
|
||||
(( date_unix > this_unix )) && break
|
||||
fi
|
||||
|
||||
# Use short dates
|
||||
date_beg=${date_beg::5} date_end=${date_end::5}
|
||||
fi
|
||||
continue
|
||||
fi
|
||||
}
|
||||
|
||||
function keep_game_info {
|
||||
@ -177,7 +200,7 @@ function info_output_term {
|
||||
echo -n "$(tput setaf 2)${tour_num} тур "
|
||||
echo "$(tput setaf 6)(${date_beg} - ${date_end})$(tput sgr0)"
|
||||
|
||||
echo -en "$output_lines" | while IFS= read line; do
|
||||
for line in "$(echo -e "$output_lines")"; do
|
||||
# Highlight player's name
|
||||
if [[ -n $PLAYER ]]; then
|
||||
players=$(grep -o "[^ ]*${PLAYER}[^ ]*" <<< "$line")
|
||||
@ -222,7 +245,7 @@ function info_output_html {
|
||||
echo " <tbody>"
|
||||
|
||||
echo -en "$output_lines" | while read white hyphen black result url; do
|
||||
[[ $result == "1/2" ]] && result="½-½"
|
||||
[[ $result == 1/2 ]] && result=½-½
|
||||
[[ -n $url ]] && result="<a href=\"${url}\">${result}</a>"
|
||||
|
||||
echo " <tr>"
|
||||
@ -242,22 +265,25 @@ function die {
|
||||
}
|
||||
|
||||
function checkargs {
|
||||
[[ $OPTARG =~ ^-[apflhv]$ ]] && die "Option -${opt}: argument not found"
|
||||
[[ $opt == f && ! $OPTARG =~ ^(term|html|lor)$ ]] && die "Incorrect FORMAT specified"
|
||||
[[ $OPTARG =~ ^-[afpolhv]$ ]] && die "Option -${opt}: argument not found"
|
||||
[[ $opt == o && ! $OPTARG =~ ^(term|html|lor)$ ]] && die "Incorrect FORMAT specified"
|
||||
}
|
||||
|
||||
FORMAT=term
|
||||
SHOW_ALL=false
|
||||
SHOW_FUTURE=false
|
||||
SHOW_LINK=false
|
||||
|
||||
while getopts ap:f:lhv opt; do
|
||||
while getopts afp:o:lhv opt; do
|
||||
case $opt in
|
||||
a) SHOW_ALL=true
|
||||
;;
|
||||
f) SHOW_FUTURE=true
|
||||
;;
|
||||
p) checkargs
|
||||
PLAYER=$OPTARG
|
||||
;;
|
||||
f) checkargs
|
||||
o) checkargs
|
||||
FORMAT=$OPTARG
|
||||
;;
|
||||
l) SHOW_LINK=true
|
||||
|
Loading…
Reference in New Issue
Block a user