Update script 'schedule'.
This commit is contained in:
parent
e23f67aa28
commit
41b13ed5eb
88
schedule
88
schedule
@ -80,7 +80,7 @@ function show_tour_sequence {
|
|||||||
|
|
||||||
# If no tour sequence given, set it to all tours
|
# If no tour sequence given, set it to all tours
|
||||||
if [[ -z $tour_seq ]]; then
|
if [[ -z $tour_seq ]]; then
|
||||||
if [[ $REPO_DIR =~ ^https://github\.com/(.*) ]]; then
|
if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then
|
||||||
tour_seq=$(curl $CURL_OPTS \
|
tour_seq=$(curl $CURL_OPTS \
|
||||||
https://api.github.com/repos/${REPO_NAME}/contents/${TOURNAMENT}/tours \
|
https://api.github.com/repos/${REPO_NAME}/contents/${TOURNAMENT}/tours \
|
||||||
| sed -En "/\"path\":/h;/\"type\": \"dir\"/{g;p;}" \
|
| sed -En "/\"path\":/h;/\"type\": \"dir\"/{g;p;}" \
|
||||||
@ -98,7 +98,7 @@ function show_tour_sequence {
|
|||||||
# *NOTE* The incorporation of a newline at the end of
|
# *NOTE* The incorporation of a newline at the end of
|
||||||
# 'tour_info' is important and allows one to read the last
|
# 'tour_info' is important and allows one to read the last
|
||||||
# line with no trailing '\n'
|
# line with no trailing '\n'
|
||||||
if [[ $REPO_DIR =~ ^https://github\.com/(.*) ]]; then
|
if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then
|
||||||
local tour_info=$(curl $CURL_OPTS --write-out '\n' \
|
local tour_info=$(curl $CURL_OPTS --write-out '\n' \
|
||||||
${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/tour_info)
|
${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/tour_info)
|
||||||
[[ -n $tour_info ]] && output_tour_info
|
[[ -n $tour_info ]] && output_tour_info
|
||||||
@ -113,63 +113,50 @@ function show_tour_sequence {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function output_tour_info {
|
function output_tour_info {
|
||||||
local tour_num date_beg date_end
|
local date_re="([0-9?]{2})\.([0-9?]{2})\.([0-9?]{4})"
|
||||||
local white black result game_date game_url
|
local white= black= result= game_date=
|
||||||
# Lines with game info
|
# Lines with game info
|
||||||
local output_lines=
|
local output_lines=
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
# Read 'tour_num'
|
# Read 'tour_num'
|
||||||
get_tour_num "$line" && continue
|
if [[ -z $tour_num ]]; then
|
||||||
|
[[ $line =~ ^"Тур №"([0-9]+) ]] && local tour_num=${BASH_REMATCH[1]}
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
# Read 'date_beg' and 'date_end'
|
# Read 'date_beg' and 'date_end'
|
||||||
get_tour_dates "$line" && continue
|
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
|
||||||
|
|
||||||
# Keep game info if needed, and store it in variables 'white',
|
# Keep game info if needed, and store it in variables 'white',
|
||||||
# 'black', 'result', and 'game_date'
|
# 'black', 'result', and 'game_date'
|
||||||
if keep_game_info "$line"; then
|
if keep_game_info; then
|
||||||
# Store the link to game in 'game_url'
|
output_lines+=$(sed -E "s/^$date_re\ +//" <<< "$line")
|
||||||
game_url=
|
# Append the link of game to the end of output line
|
||||||
if $SHOW_LINK; then
|
if $SHOW_LINK; then
|
||||||
[[ -n $result ]] && store_game_url
|
[[ -n $result ]] && append_game_url
|
||||||
fi
|
fi
|
||||||
|
output_lines+="\n"
|
||||||
output_lines+="${white} ${black} ${result} ${game_url}\n"
|
|
||||||
fi
|
fi
|
||||||
done <<< "$tour_info"
|
done <<< "$tour_info"
|
||||||
|
|
||||||
[[ -n $output_lines ]] && eval "info_output_$FORMAT \"${output_lines}\""
|
[[ -n $output_lines ]] && eval "info_output_$FORMAT \"${output_lines}\""
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_tour_num {
|
|
||||||
if [[ $1 =~ ^"Тур №"([0-9]+) ]]; then
|
|
||||||
tour_num=${BASH_REMATCH[1]}
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_tour_dates {
|
|
||||||
local date_re="[0-9?]{2}\.[0-9?]{2}\.[0-9?]{4}"
|
|
||||||
|
|
||||||
if [[ $1 =~ ^"Время проведения:"\ +($date_re)\ +-\ +($date_re) ]]; then
|
|
||||||
date_beg=${BASH_REMATCH[1]} date_end=${BASH_REMATCH[2]}
|
|
||||||
# Use short dates
|
|
||||||
date_beg=${date_beg::5} date_end=${date_end::5}
|
|
||||||
return 0
|
|
||||||
else
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
function keep_game_info {
|
function keep_game_info {
|
||||||
local date_re="([0-9?]{2})\.([0-9?]{2})\.([0-9?]{4})"
|
|
||||||
local res_re="(1|1/2|0)-(1|1/2|0)"
|
local res_re="(1|1/2|0)-(1|1/2|0)"
|
||||||
local line=$1 keep=1
|
local keep=1
|
||||||
|
|
||||||
if [[ $line =~ ^($date_re)\ +([^\ ]+)\ +-\ +([^\ ]+)\ *($res_re)? ]]; then
|
if [[ $line =~ ^$date_re\ +([^\ ]+)\ +-\ +([^\ ]+)(\ +$res_re)? ]]; then
|
||||||
white=${BASH_REMATCH[5]} black=${BASH_REMATCH[6]} result=${BASH_REMATCH[7]}
|
white=${BASH_REMATCH[4]} black=${BASH_REMATCH[5]} result=${BASH_REMATCH[6]// /}
|
||||||
game_date=${BASH_REMATCH[4]}-${BASH_REMATCH[3]}-${BASH_REMATCH[2]}
|
game_date=${BASH_REMATCH[3]}-${BASH_REMATCH[2]}-${BASH_REMATCH[1]}
|
||||||
|
|
||||||
# If the player was passed as an argument, check if it is his game or not
|
# If the player was passed as an argument, check if it is his game or not
|
||||||
if [[ -z $PLAYER || $white =~ $PLAYER || $black =~ $PLAYER ]]; then
|
if [[ -z $PLAYER || $white =~ $PLAYER || $black =~ $PLAYER ]]; then
|
||||||
@ -185,17 +172,20 @@ function keep_game_info {
|
|||||||
return $keep
|
return $keep
|
||||||
}
|
}
|
||||||
|
|
||||||
function store_game_url {
|
function append_game_url {
|
||||||
local tour=$(printf "%02g" "$tour_num")
|
local tour=$(printf "%02g" "$tour_num")
|
||||||
local game_dir=${game_date}-${white}-vs-${black}
|
local game_dir=${game_date}-${white}-vs-${black}
|
||||||
local pgn_url=${REPO}/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn
|
|
||||||
|
|
||||||
while read line; do
|
if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then
|
||||||
# Search for a URL inside PGN file
|
local pgn_text=$(curl $CURL_OPTS \
|
||||||
[[ $line =~ "[Site \""([a-z]+:[^\"]+)"\"]" ]]
|
${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn)
|
||||||
game_url=${BASH_REMATCH[1]}
|
else
|
||||||
[[ -n $game_url ]] && break
|
local pgn_text=$(cat ${REPO_DIR}/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn)
|
||||||
done <<< $(curl -q --fail --location --silent "$pgn_url")
|
fi
|
||||||
|
|
||||||
|
local game_url=$(echo "$pgn_text" | grep -Eo "\[Site \"[a-z]+:[^\"]+\"\]" \
|
||||||
|
| sed -E "s/\[Site \"([a-z]+:[^\"]+)\"\]/\1/")
|
||||||
|
output_lines+=" $game_url"
|
||||||
}
|
}
|
||||||
|
|
||||||
function info_output_term {
|
function info_output_term {
|
||||||
@ -227,7 +217,7 @@ function info_output_lor {
|
|||||||
echo "[b]${tour_num} тур (${date_beg} - ${date_end})[/b]"
|
echo "[b]${tour_num} тур (${date_beg} - ${date_end})[/b]"
|
||||||
echo "[list]"
|
echo "[list]"
|
||||||
|
|
||||||
echo -en "$1" | while read white black result url; do
|
echo -en "$1" | while read white hyphen black result url; do
|
||||||
[[ -n $url ]] && result="[url=${url}]${result}[/url]"
|
[[ -n $url ]] && result="[url=${url}]${result}[/url]"
|
||||||
|
|
||||||
echo " [*] [user]${white}[/user] - [user]${black}[/user] ${result}"
|
echo " [*] [user]${white}[/user] - [user]${black}[/user] ${result}"
|
||||||
@ -246,7 +236,7 @@ function info_output_html {
|
|||||||
echo " </caption>"
|
echo " </caption>"
|
||||||
echo " <tbody>"
|
echo " <tbody>"
|
||||||
|
|
||||||
echo -en "$1" | while read white black result url; do
|
echo -en "$1" | while read white hyphen black result url; do
|
||||||
[[ -n $url ]] && result="<a href=\"${url}\">${result}</a>"
|
[[ -n $url ]] && result="<a href=\"${url}\">${result}</a>"
|
||||||
|
|
||||||
echo " <tr>"
|
echo " <tr>"
|
||||||
|
Loading…
Reference in New Issue
Block a user