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() {
|
||||
local sequence
|
||||
local tour_info
|
||||
|
||||
# Generate the sequence of tours to search in
|
||||
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
|
||||
# Reduce REPO to a canonical form
|
||||
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
|
||||
# 'tour_info' (--write-out '\n') is important and allows one
|
||||
# to read the last line with no trailing '\n'
|
||||
local tour_info="$(curl -q --fail --silent --write-out '\n' $info_url)"
|
||||
if [[ -n "$@" ]]; then
|
||||
for num in $@; do
|
||||
fetch_tour_info "$num" && output_tour_info
|
||||
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
|
||||
if [[ -n "$tour_info" ]]; then
|
||||
fetch_tour_info() {
|
||||
# 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 white black result game_date game_url
|
||||
# Lines with game info
|
||||
@ -75,8 +86,8 @@ show_tour_sequence() {
|
||||
get_tour_num "$line" && continue
|
||||
get_tour_dates "$line" && continue
|
||||
|
||||
# Keep game info if needed, and store it in variables
|
||||
# 'while', 'black', 'result', and 'game_date'
|
||||
# Keep game info if needed, and store it in variables 'white',
|
||||
# 'black', 'result', and 'game_date'
|
||||
if keep_game_info "$line"; then
|
||||
# Fix result
|
||||
case "$result" in
|
||||
@ -96,13 +107,6 @@ show_tour_sequence() {
|
||||
done <<< "$tour_info"
|
||||
|
||||
[[ -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() {
|
||||
@ -165,9 +169,9 @@ keep_game_info() {
|
||||
}
|
||||
|
||||
store_game_url() {
|
||||
local tour=$(printf "%02g" "$tour_num")
|
||||
local tour=$(printf "%02g" "$num")
|
||||
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
|
||||
# Search for a URL inside PGN file
|
||||
|
Loading…
Reference in New Issue
Block a user