Update script 'schedule'.
This commit is contained in:
		
							
								
								
									
										88
									
								
								schedule
									
									
									
									
									
								
							
							
						
						
									
										88
									
								
								schedule
									
									
									
									
									
								
							| @@ -80,7 +80,7 @@ function show_tour_sequence { | ||||
|  | ||||
|     # If no tour sequence given, set it to all tours | ||||
|     if [[ -z $tour_seq ]]; then | ||||
|         if [[ $REPO_DIR =~ ^https://github\.com/(.*) ]]; then | ||||
|         if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then | ||||
|             tour_seq=$(curl $CURL_OPTS \ | ||||
|                 https://api.github.com/repos/${REPO_NAME}/contents/${TOURNAMENT}/tours \ | ||||
|                 | 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 | ||||
|         # 'tour_info' is important and allows one to read the last | ||||
|         # 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' \ | ||||
|                 ${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/tour_info) | ||||
|             [[ -n $tour_info ]] && output_tour_info | ||||
| @@ -113,63 +113,50 @@ function show_tour_sequence { | ||||
| } | ||||
|  | ||||
| function output_tour_info { | ||||
|     local tour_num date_beg date_end | ||||
|     local white black result game_date game_url | ||||
|     local date_re="([0-9?]{2})\.([0-9?]{2})\.([0-9?]{4})" | ||||
|     local white= black= result= game_date= | ||||
|     # Lines with game info | ||||
|     local output_lines= | ||||
|  | ||||
|     while read line; do | ||||
|         # 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' | ||||
|         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', | ||||
|         # 'black', 'result', and 'game_date' | ||||
|         if keep_game_info "$line"; then | ||||
|             # Store the link to game in 'game_url' | ||||
|             game_url= | ||||
|         if keep_game_info; then | ||||
|             output_lines+=$(sed -E "s/^$date_re\ +//" <<< "$line") | ||||
|             # Append the link of game to the end of output line | ||||
|             if $SHOW_LINK; then | ||||
|                 [[ -n $result ]] && store_game_url | ||||
|                 [[ -n $result ]] && append_game_url | ||||
|             fi | ||||
|  | ||||
|             output_lines+="${white} ${black} ${result} ${game_url}\n" | ||||
|             output_lines+="\n" | ||||
|         fi | ||||
|     done <<< "$tour_info" | ||||
|  | ||||
|     [[ -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 { | ||||
|     local date_re="([0-9?]{2})\.([0-9?]{2})\.([0-9?]{4})" | ||||
|     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 | ||||
|         white=${BASH_REMATCH[5]} black=${BASH_REMATCH[6]} result=${BASH_REMATCH[7]} | ||||
|         game_date=${BASH_REMATCH[4]}-${BASH_REMATCH[3]}-${BASH_REMATCH[2]} | ||||
|     if [[ $line =~ ^$date_re\ +([^\ ]+)\ +-\ +([^\ ]+)(\ +$res_re)? ]]; then | ||||
|         white=${BASH_REMATCH[4]} black=${BASH_REMATCH[5]} result=${BASH_REMATCH[6]// /} | ||||
|         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 [[ -z $PLAYER || $white =~ $PLAYER || $black =~ $PLAYER ]]; then | ||||
| @@ -185,17 +172,20 @@ function keep_game_info { | ||||
|     return $keep | ||||
| } | ||||
|  | ||||
| function store_game_url { | ||||
| function append_game_url { | ||||
|     local tour=$(printf "%02g" "$tour_num") | ||||
|     local game_dir=${game_date}-${white}-vs-${black} | ||||
|     local pgn_url=${REPO}/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn | ||||
|  | ||||
|     while read line; do | ||||
|         # Search for a URL inside PGN file | ||||
|         [[ $line =~ "[Site \""([a-z]+:[^\"]+)"\"]" ]] | ||||
|         game_url=${BASH_REMATCH[1]} | ||||
|         [[ -n $game_url ]] && break | ||||
|     done <<< $(curl -q --fail --location --silent "$pgn_url") | ||||
|     if [[ $REPO_DIR =~ ^https://github\.com/ ]]; then | ||||
|         local pgn_text=$(curl $CURL_OPTS \ | ||||
|             ${REPO_DIR}/raw/master/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn) | ||||
|     else | ||||
|         local pgn_text=$(cat ${REPO_DIR}/${TOURNAMENT}/tours/${tour}/${game_dir}/1.pgn) | ||||
|     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 { | ||||
| @@ -227,7 +217,7 @@ function info_output_lor { | ||||
|     echo "[b]${tour_num} тур (${date_beg} - ${date_end})[/b]" | ||||
|     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]" | ||||
|  | ||||
|         echo "  [*] [user]${white}[/user] - [user]${black}[/user] ${result}" | ||||
| @@ -246,7 +236,7 @@ function info_output_html { | ||||
|     echo "    </caption>" | ||||
|     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>" | ||||
|  | ||||
|         echo "      <tr>" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user