From a129a173b73b56d537d46662a95451ecf67ac6ae Mon Sep 17 00:00:00 2001 From: Aki Kareha Date: Sat, 22 Feb 2025 08:59:59 +0900 Subject: [PATCH] add script to download and update holiday CSV file --- .gitignore | 2 ++ clean | 2 ++ update | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 .gitignore create mode 100755 clean create mode 100755 update diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8a90164 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.csv diff --git a/clean b/clean new file mode 100755 index 0000000..cd49ec9 --- /dev/null +++ b/clean @@ -0,0 +1,2 @@ +#!/bin/sh +rm -f *.csv diff --git a/update b/update new file mode 100755 index 0000000..ddb71d0 --- /dev/null +++ b/update @@ -0,0 +1,34 @@ +#!/bin/sh + +# Settings +CSV_URL="https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv" + +# Internal configuration settings +TMP_CSV_FILE="holidays-jp-tmp.csv" +RAW_CSV_FILE="holidays-jp-raw.csv" +CSV_FILE="holidays-jp.csv" + +EXIT_SUCCESS=0 +EXIT_FAILURE=1 + +# Verify the required runtime environment +if ! command -v curl > /dev/null; then + echo "This script requires \"curl\" to be installed. Please install it and try again." + exit $EXIT_FAILURE +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 +fi + +# Run +curl -sS -L -o $TMP_CSV_FILE $CSV_URL +if ! diff -q $RAW_CSV_FILE $TMP_CSV_FILE > /dev/null 2>&1; then + mv $TMP_CSV_FILE $RAW_CSV_FILE + nkf -w $RAW_CSV_FILE > $CSV_FILE +else + rm $TMP_CSV_FILE +fi + +# Exit +exit $EXIT_SUCCESS