trim old holidays
This commit is contained in:
		
							
								
								
									
										21
									
								
								update
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								update
									
									
									
									
									
								
							@@ -8,14 +8,16 @@ EXIT_SUCCESS=0
 | 
				
			|||||||
EXIT_FAILURE=1
 | 
					EXIT_FAILURE=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Verify the required runtime environment
 | 
					# Verify the required runtime environment
 | 
				
			||||||
if ! command -v curl >/dev/null; then
 | 
					verify_command() {
 | 
				
			||||||
  echo "This script requires \"curl\" to be installed. Please install it and try again."
 | 
					  if ! command -v $1 >/dev/null; then
 | 
				
			||||||
 | 
					    echo "This script requires \"$1\" to be installed. Please install it and try again."
 | 
				
			||||||
    exit $EXIT_FAILURE
 | 
					    exit $EXIT_FAILURE
 | 
				
			||||||
fi
 | 
					  fi
 | 
				
			||||||
if ! command -v nkf >/dev/null; then
 | 
					}
 | 
				
			||||||
  echo "This script requires \"nkf\" to be installed. Please install it and try again."
 | 
					
 | 
				
			||||||
  exit $EXIT_FAILURE
 | 
					verify_command "curl"
 | 
				
			||||||
fi
 | 
					verify_command "nkf"
 | 
				
			||||||
 | 
					verify_command "awk"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Logging
 | 
					# Logging
 | 
				
			||||||
CURRENT_MONTH=$(date "+%Yw%U%z")
 | 
					CURRENT_MONTH=$(date "+%Yw%U%z")
 | 
				
			||||||
@@ -45,13 +47,16 @@ mkdir -p $LOG_DIR
 | 
				
			|||||||
# Internal configuration settings
 | 
					# Internal configuration settings
 | 
				
			||||||
TMP_CSV_FILE="holidays-jp-tmp.csv"
 | 
					TMP_CSV_FILE="holidays-jp-tmp.csv"
 | 
				
			||||||
RAW_CSV_FILE="holidays-jp-raw.csv"
 | 
					RAW_CSV_FILE="holidays-jp-raw.csv"
 | 
				
			||||||
 | 
					ALL_CSV_FILE="holidays-jp-all.csv"
 | 
				
			||||||
CSV_FILE="holidays-jp.csv"
 | 
					CSV_FILE="holidays-jp.csv"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Run
 | 
					# Run
 | 
				
			||||||
curl -sS -L -o $TMP_CSV_FILE $CSV_URL
 | 
					curl -sS -L -o $TMP_CSV_FILE $CSV_URL
 | 
				
			||||||
if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then
 | 
					if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE >/dev/null 2>&1; then
 | 
				
			||||||
  mv $TMP_CSV_FILE $RAW_CSV_FILE
 | 
					  mv $TMP_CSV_FILE $RAW_CSV_FILE
 | 
				
			||||||
  nkf -w $RAW_CSV_FILE >$CSV_FILE
 | 
					  nkf -w $RAW_CSV_FILE >$ALL_CSV_FILE
 | 
				
			||||||
 | 
					  current_year=$(date +'%Y')
 | 
				
			||||||
 | 
					  tail -n +2 $ALL_CSV_FILE | awk -v cy="$current_year" -F'/' '{ if ($1 >= cy) print }' >$CSV_FILE
 | 
				
			||||||
  log "Changed"
 | 
					  log "Changed"
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
  log "No Change"
 | 
					  log "No Change"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user