Edited at

あれ?そっち今日休みなの?大事な時に海外開発チームの祝日が覚えられないのでSlackに教えてもらう


はじめに

うちのチームは、日本、イギリス、インドのマルチサイト開発しています。海外とやると、しばしばタイトルみたいにあっちの祝日忘れてて、「あれ、今日話せないのか、時差もあるし次話せるのは..... おぃ!」ってなって、リリース前は特にあせることがあるのでなんとかしたいですね。

ちょっと探したところ、GoogleカレンダーのAPIで祝日を取ってきてslackへってやってるのが多いですね。なんかめんどくさいんで、もっと簡単にやれないかなと思っていたところ、gcalコマンドでも各国の祝日とれることがわかりましたのでそれでやってみます。


Slackのリマインダ

要は、この形にすればslackはリマインドしてくれる。

/remind [@someone or #channel] "[what]" [when]

おなじみのこんな感じでリマインド。目立つように国旗もつけたい。

Screen Shot 2019-02-23 at 14.52.35.png

Screen Shot 2019-02-24 at 10.41.04.png


インストール

gcalをインストール。macでやってます。

mac-mini:~ brew install gcal


祝日を表示する

gcal --holiday-list --cc-holiday=JP

Eternal holiday list:                      The year 2019 is NO leap year

New Year's Day (JP) + Tue, Jan 1st 2019 = -53 days
Bank Holiday (JP) * Wed, Jan 2nd 2019 = -52 days
Bank Holiday (JP) * Thu, Jan 3rd 2019 = -51 days
Coming of Age Day (JP) + Tue, Jan 15th 2019 = -39 days
Spring Festival (JP) - Sat, Feb 2nd 2019 = -21 days
Season Change/Bean-Festival (JP) - Sun, Feb 3rd 2019 = -20 days
Sapporo Snow Festival (JP) - Thu, Feb 7th 2019 = -16 days
National Foundation Day (JP) + Mon, Feb 11th 2019 = -12 days
St Valentine's Day (JP) - Thu, Feb 14th 2019 = -9 days
Peach Festival (JP) - Mon, Mar 4th 2019 = +9 days
Equinox Day (JP) + Thu, Mar 21st 2019 = +26 days
Buddha's Birthday (JP) - Mon, Apr 8th 2019 = +44 days
Greenery Day (JP) + Mon, Apr 29th 2019 = +65 days
Constitution Anniversary (JP) + Fri, May 3rd 2019 = +69 days
Children's Day (JP) + Mon, May 6th 2019 = +72 days
Star Festival (JP) - Mon, Jul 8th 2019 = +135 days
Marine Day (JP) + Sat, Jul 20th 2019 = +147 days
Feast of Fortune (JP) - Tue, Aug 13th 2019 = +171 days
Feast of Fortune (JP) - Wed, Aug 14th 2019 = +172 days
Feast of Fortune (JP) - Thu, Aug 15th 2019 = +173 days
Feast of Fortune (JP) - Fri, Aug 16th 2019 = +174 days
Chrysanthenum Day (JP) - Mon, Sep 9th 2019 = +198 days
Respect for the Aged Day (JP) + Mon, Sep 16th 2019 = +205 days
Equinox Day (JP) + Mon, Sep 23rd 2019 = +212 days
Health and Sport's Day (JP) + Thu, Oct 10th 2019 = +229 days
Culture Day (JP) + Mon, Nov 4th 2019 = +254 days
7-5-3 Festival (JP) - Fri, Nov 15th 2019 = +265 days
Labour Thanksgiving Day (JP) + Sat, Nov 23rd 2019 = +273 days
Soot-Sweeping Day (JP) - Fri, Dec 13th 2019 = +293 days
Japanese New Year's Day (JP) - Sun, Dec 22nd 2019 = +302 days
Emperor's Birthday (JP) + Mon, Dec 23rd 2019 = +303 days
Bank Holiday (JP) * Tue, Dec 31st 2019 = +311 days

あれ、日本ってこんなに祝日あったっけ?.... *, +, -のフラグのうち+のやつがいわゆる国民の祝日な気がする.... なるほど、大文字の-Nにするとリーガルホリデーのみになるみたい。国指定は-qでもいける。

mac-mini:~ $ gcal -N -q JP 

Eternal holiday list: The year 2019 is NO leap year

New Year's Day (JP) + Tue, Jan 1st 2019 = -53 days
Coming of Age Day (JP) + Tue, Jan 15th 2019 = -39 days
National Foundation Day (JP) + Mon, Feb 11th 2019 = -12 days
Equinox Day (JP) + Thu, Mar 21st 2019 = +26 days
Greenery Day (JP) + Mon, Apr 29th 2019 = +65 days
Constitution Anniversary (JP) + Fri, May 3rd 2019 = +69 days
Children's Day (JP) + Mon, May 6th 2019 = +72 days
Marine Day (JP) + Sat, Jul 20th 2019 = +147 days
Respect for the Aged Day (JP) + Mon, Sep 16th 2019 = +205 days
Equinox Day (JP) + Mon, Sep 23rd 2019 = +212 days
Health and Sport's Day (JP) + Thu, Oct 10th 2019 = +229 days
Culture Day (JP) + Mon, Nov 4th 2019 = +254 days
Labour Thanksgiving Day (JP) + Sat, Nov 23rd 2019 = +273 days
Emperor's Birthday (JP) + Mon, Dec 23rd 2019 = +303 days

おし、これや!.... いや、なんか全然違う。このカレンダー古い。連休作るために月曜日に動いた祝日が反映されていない。うーん。まあ、やるだけやるか。


今日は祝日です

今日は祝日だとslackでみんなに伝えるワンライナー


gcal -N -q JP | sed -e s/"(JP)"/"in :flag-jp:"/ | awk -F'[,=+]' '{print "/remind me \047Today is " $1"\047" " in " $5}' | sed -E 's/:[ ]+/:/g'

超ざっくり。+awkの区切り文字として使われているので、過去の祝日は日数が表示されないという雑さ。今から未来の祝日しか通知されない、過去は振り向かない仕様。

/remind me 'Today is ' in 

/remind me 'Today is Eternal holiday list:The year 2019 is NO leap year' in
/remind me 'Today is ' in
/remind me 'Today is New Year's Day in :flag-jp:' in
/remind me '
Today is Coming of Age Day in :flag-jp:' in
/remind me '
Today is National Foundation Day in :flag-jp:' in
/remind me '
Today is Equinox Day in :flag-jp:' in 26 days
/remind me '
Today is Greenery Day in :flag-jp:' in 65 days
/remind me '
Today is Constitution Anniversary in :flag-jp:' in 69 days
/remind me '
Today is Children's Day in :flag-jp:' in 72 days
/remind me 'Today is Marine Day in :flag-jp:' in 147 days
/remind me 'Today is Respect for the Aged Day in :flag-jp:' in 205 days
/remind me 'Today is Equinox Day in :flag-jp:' in 212 days
/remind me 'Today is Health and Sport's Day in :flag-jp:' in 229 days
/remind me '
Today is Culture Day in :flag-jp:' in 254 days
/remind me '
Today is Labour Thanksgiving Day in :flag-jp:' in 273 days
/remind me '
Today is Emperor's Birthday in :flag-jp:' in 303 days

まあ、当日通知もいいけど、「俺働きませんって、今日言われてもなぁ」...となるのでやはり前日に伝えるべきですね。


明日は祝日です

すいません、$5から1引いただけです。

gcal -N -q JP | sed -e s/"(JP)"/"in :flag-jp:"/ |  awk -F'[,=+]' '{print "/remind me \047Tomorrow is " $1 "\047" " in " $5-1 " days"}' | sed -E 's/:[ ]+/:/g'

/remind me 'Tomorrow is ' in -1 days

/remind me 'Tomorrow is Eternal holiday list:The year 2019 is NO leap year' in -1 days
/remind me 'Tomorrow is ' in -1 days
/remind me 'Tomorrow is New Year's Day in :flag-jp:' in -1 days
/remind me 'Tomorrow is Coming of Age Day in :flag-jp:' in -1 days
/remind me 'Tomorrow is National Foundation Day in :flag-jp:' in -1 days
/remind me 'Tomorrow is Equinox Day in :flag-jp:' in 25 days
/remind me 'Tomorrow is Greenery Day in :flag-jp:' in 64 days
/remind me 'Tomorrow is Constitution Anniversary in :flag-jp:' in 68 days
/remind me 'Tomorrow is Children's Day in :flag-jp:' in 71 days
/remind me 'Tomorrow is Marine Day in :flag-jp:' in 146 days
/remind me 'Tomorrow is Respect for the Aged Day in :flag-jp:' in 204 days
/remind me 'Tomorrow is Equinox Day in :flag-jp:' in 211 days
/remind me 'Tomorrow is Health and Sport's Day in :flag-jp:' in 228 days
/remind me 'Tomorrow is Culture Day in :flag-jp:' in 253 days
/remind me 'Tomorrow is Labour Thanksgiving Day in :flag-jp:' in 272 days
/remind me 'Tomorrow is Emperor's Birthday in :flag-jp:' in 302 days

あとは、これをslackにはりつければよい。あ、me#チャネル名 に置き換えるのを忘れずに。


イギリスとインドの祝日は?

イギリスは9日で、インドはたったの7日? OMG.

$ gcal -N -q GB_EN

Eternal holiday list: The year 2019 is NO leap year

New Year's Day (GB_EN) + Tue, Jan 1st 2019 = -53 days
Good Friday (GB_EN) + Fri, Apr 19th 2019 = +55 days
Easter Sunday (GB_EN) + Sun, Apr 21st 2019 = +57 days
Easter Monday (GB_EN) + Mon, Apr 22nd 2019 = +58 days
May Day (GB_EN) + Mon, May 6th 2019 = +72 days
Bank Holiday (GB_EN) + Mon, May 27th 2019 = +93 days
Bank Holiday (GB_EN) + Mon, Aug 26th 2019 = +184 days
Christmas Day (GB_EN) + Wed, Dec 25th 2019 = +305 days
Boxing Day (GB_EN) + Thu, Dec 26th 2019 = +306 days

$ gcal -N -q IN

Eternal holiday list: The year 2019 is NO leap year

New Year's Day (IN) + Tue, Jan 1st 2019 = -53 days
Republic Day (IN) + Sat, Jan 26th 2019 = -28 days
Good Friday (IN) + Fri, Apr 19th 2019 = +55 days
Eid-al-Fitr (IN) + Wed, Jun 5th 2019 = +102 days
Independence Day (IN) + Thu, Aug 15th 2019 = +173 days
Mahatma Gandhi's Birthday (IN) + Wed, Oct 2nd 2019 = +221 days
Christmas Day (IN) + Wed, Dec 25th 2019 = +305 days


出会い

gcal知ったのは、このサイトのおかげです。多謝。

待ち遠しい次の祝日がコマンドラインでわかる!‐cal‐ 端末にカレンダーを表示しよう


書き直し

ちょっと最初のバージョンは雑すぎたので、書き直しました。過去の祝日は表示なし。日本だけじゃなくて各国の祝日を入れました。#channelを変更して使えます。

gcal -N -q jp+in+gb_en | sed -E 's/[ ]+/ /g' | sed 's/\(.*)\).*\([+-].*\) days/\1 \2/' | awk -F')' '$2>0 {print}' | awk -F'+' '{print "/remind #channel \"Tomorrow is " $1 "- Have a good holiday.\" in " $2-1 " days"}' | sed s/"(JP)"/"in :flag-jp:"/ | sed s/"(GB_EN)"/"in :flag-gb:"/ | sed s/"(IN)"/"in :flag-in:"/

出力はこうなる

/remind #channel "Tomorrow is Equinox Day in :flag-jp: - Have a good holiday." in 25 days

/remind #channel "Tomorrow is Good Friday in :flag-gb: - Have a good holiday." in 54 days
/remind #channel "Tomorrow is Good Friday in :flag-in: - Have a good holiday." in 54 days
/remind #channel "Tomorrow is Easter Sunday in :flag-gb: - Have a good holiday." in 56 days
/remind #channel "Tomorrow is Easter Monday in :flag-gb: - Have a good holiday." in 57 days
/remind #channel "Tomorrow is Greenery Day in :flag-jp: - Have a good holiday." in 64 days
/remind #channel "Tomorrow is Constitution Anniversary in :flag-jp: - Have a good holiday." in 68 days
/remind #channel "Tomorrow is Children's Day in :flag-jp: - Have a good holiday." in 71 days
/remind #channel "Tomorrow is May Day in :flag-gb: - Have a good holiday." in 71 days
/remind #channel "Tomorrow is Bank Holiday in :flag-gb: - Have a good holiday." in 92 days
/remind #channel "Tomorrow is Eid-al-Fitr in :flag-in: - Have a good holiday." in 101 days
/remind #channel "Tomorrow is Marine Day in :flag-jp: - Have a good holiday." in 146 days
/remind #channel "Tomorrow is Independence Day in :flag-in: - Have a good holiday." in 172 days
/remind #channel "Tomorrow is Bank Holiday in :flag-gb: - Have a good holiday." in 183 days
/remind #channel "Tomorrow is Respect for the Aged Day in :flag-jp: - Have a good holiday." in 204 days
/remind #channel "Tomorrow is Equinox Day in :flag-jp: - Have a good holiday." in 211 days
/remind #channel "Tomorrow is Mahatma Gandhi's Birthday in :flag-in: - Have a good holiday." in 220 days
/remind #channel "Tomorrow is Health and Sport's Day in :flag-jp: - Have a good holiday." in 228 days
/remind #channel "Tomorrow is Culture Day in :flag-jp: - Have a good holiday." in 253 days
/remind #channel "Tomorrow is Labour Thanksgiving Day in :flag-jp: - Have a good holiday." in 272 days
/remind #channel "Tomorrow is Emperor's Birthday in :flag-jp: - Have a good holiday." in 302 days
/remind #channel "Tomorrow is Christmas Day in :flag-gb: - Have a good holiday." in 304 days
/remind #channel "Tomorrow is Christmas Day in :flag-in: - Have a good holiday." in 304 days
/remind #channel "Tomorrow is Boxing Day in :flag-gb: - Have a good holiday." in 305 days