Script 'schedule': improve the form of loops in a tour sequence.
This commit is contained in:
parent
76cf82bad6
commit
1ff814c2d3
62
schedule
62
schedule
@ -44,28 +44,39 @@ version() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show_tour_sequence() {
|
show_tour_sequence() {
|
||||||
local sequence
|
local tour_info
|
||||||
|
|
||||||
# Generate the sequence of tours to search in
|
# Reduce REPO to a canonical form
|
||||||
if [[ -z "$@" ]]; then
|
|
||||||
sequence=$(seq -f "%02g" 1 99)
|
|
||||||
else
|
|
||||||
# Change tour numbers: '1' -> '01', '2' -> '02', and so on
|
|
||||||
sequence=$(for i in "$@"; do printf "%02g " "$i"; done)
|
|
||||||
fi
|
|
||||||
|
|
||||||
for tour in $sequence; do
|
|
||||||
convert_repo_url
|
convert_repo_url
|
||||||
local base_url="${REPO}/${TOURNAMENT}"
|
|
||||||
local info_url="${base_url}/tours/${tour}/tour_info"
|
|
||||||
|
|
||||||
# *NOTE* The incorporation of a newline at the end of
|
if [[ -n "$@" ]]; then
|
||||||
# 'tour_info' (--write-out '\n') is important and allows one
|
for num in $@; do
|
||||||
# to read the last line with no trailing '\n'
|
fetch_tour_info "$num" && output_tour_info
|
||||||
local tour_info="$(curl -q --fail --silent --write-out '\n' $info_url)"
|
done
|
||||||
|
else
|
||||||
|
# If the tour numbers were not passed as arguments, exit once
|
||||||
|
# the first non-existing 'tour_info' is reached
|
||||||
|
num=1
|
||||||
|
while fetch_tour_info "$num"; do
|
||||||
|
output_tour_info
|
||||||
|
num=$((num+1))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Produce output only if 'tour_info' exists
|
fetch_tour_info() {
|
||||||
if [[ -n "$tour_info" ]]; then
|
# Change tour numbers: '1' -> '01', '2' -> '02', and so on
|
||||||
|
local tour=$(printf "%02g" "$num")
|
||||||
|
|
||||||
|
# *NOTE* The incorporation of a newline at the end of 'tour_info'
|
||||||
|
# (--write-out '\n') is important and allows one to read the last
|
||||||
|
# line with no trailing '\n'
|
||||||
|
local info_url="${REPO}/${TOURNAMENT}/tours/${tour}/tour_info"
|
||||||
|
tour_info="$(curl -q --fail --silent --write-out '\n' $info_url)"
|
||||||
|
return `[[ -n "$tour_info" ]]`
|
||||||
|
}
|
||||||
|
|
||||||
|
output_tour_info() {
|
||||||
local tour_num date_beg date_end
|
local tour_num date_beg date_end
|
||||||
local white black result game_date game_url
|
local white black result game_date game_url
|
||||||
# Lines with game info
|
# Lines with game info
|
||||||
@ -75,8 +86,8 @@ show_tour_sequence() {
|
|||||||
get_tour_num "$line" && continue
|
get_tour_num "$line" && continue
|
||||||
get_tour_dates "$line" && continue
|
get_tour_dates "$line" && continue
|
||||||
|
|
||||||
# Keep game info if needed, and store it in variables
|
# Keep game info if needed, and store it in variables 'white',
|
||||||
# 'while', 'black', 'result', and 'game_date'
|
# 'black', 'result', and 'game_date'
|
||||||
if keep_game_info "$line"; then
|
if keep_game_info "$line"; then
|
||||||
# Fix result
|
# Fix result
|
||||||
case "$result" in
|
case "$result" in
|
||||||
@ -96,13 +107,6 @@ show_tour_sequence() {
|
|||||||
done <<< "$tour_info"
|
done <<< "$tour_info"
|
||||||
|
|
||||||
[[ -n "$output_lines" ]] && eval "info_output_$FORMAT \"${output_lines}\""
|
[[ -n "$output_lines" ]] && eval "info_output_$FORMAT \"${output_lines}\""
|
||||||
|
|
||||||
else
|
|
||||||
# If the tour numbers were not passed as arguments, exit
|
|
||||||
# once the first non-existing 'tour_info' is reached
|
|
||||||
[[ -z "$@" ]] && break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
}
|
||||||
|
|
||||||
convert_repo_url() {
|
convert_repo_url() {
|
||||||
@ -165,9 +169,9 @@ keep_game_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
store_game_url() {
|
store_game_url() {
|
||||||
local tour=$(printf "%02g" "$tour_num")
|
local tour=$(printf "%02g" "$num")
|
||||||
local game_dir="${game_date}-${white}-vs-${black}"
|
local game_dir="${game_date}-${white}-vs-${black}"
|
||||||
local pgn_url="${base_url}/tours/${tour}/${game_dir}/1.pgn"
|
local pgn_url="${REPO}/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn"
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
# Search for a URL inside PGN file
|
# Search for a URL inside PGN file
|
||||||
|
Loading…
Reference in New Issue
Block a user