Skip to content

Instantly share code, notes, and snippets.

@mitoma
Last active March 4, 2022 02:03
Show Gist options
  • Save mitoma/4509618 to your computer and use it in GitHub Desktop.
Save mitoma/4509618 to your computer and use it in GitHub Desktop.
shellでGoogleカレンダーから祝日を判定するにはこういう風に判定するといい。jenkinsなどで祝日稼働したくないジョブがあるときに便利だと思う。
#!/bin/sh
# 独自で休日を定義する場合は独自で作ったGoogleカレンダーのIDを指定する
# ここで指定しているカレンダーは公開カレンダー「日本の休日」
CALENDAR_ID='ja.japanese%23holiday%40group.v.calendar.google.com'
# GoogleカレンダーのAPI KEYを設定する。
API_KEY='API KEY'
DATE=`date +%Y-%m-%d`
MIN_TIME="${DATE}T00%3A00%3A00.000Z"
MAX_TIME="${DATE}T00%3A00%3A01.000Z"
URL="https://www.googleapis.com/calendar/v3/calendars/${CALENDAR_ID}/events?timeMax=${MAX_TIME}&timeMin=${MIN_TIME}&key=${API_KEY}"
# FIXME バグっとるらしい
IS_HOLIDAY=`curl -s "${URL}" | grep items | wc -l`
if [ ${IS_HOLIDAY} -gt 0 ]
then
echo "holiday"
else
echo "not holiday"
fi
@wang-zhijun
Copy link

スクリプトの中のMIN_TIMEとMAX_TIMEはどういう役割なのか教えていただけますか?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment