Created
April 1, 2021 11:23
-
-
Save matoken/694402a8a8aef819c92838e76ace1e4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# khalコマンドで今日の予定を入手してDiscordにpostする | |
# https://matoken.org/blog/2021/03/31/post-your-calendar-to-discord-with-webhooks/ | |
# DiscordのWebhook URL | |
# 以下のURLを参考に入手して設定する | |
# https://support.discord.com/hc/ja/articles/228383668-%E3%82%BF%E3%82%A4%E3%83%88%E3%83%AB-Webhooks%E3%81%B8%E3%81%AE%E5%BA%8F%E7%AB%A0 | |
DISCORD_WEBHOOK='https://ptb.discord.com/api/webhooks/…………' | |
# khal | |
# list -> 一覧表示 | |
# --format "{title}" -> タイトルだけ表示 | |
# today -> 今日から | |
# today -> 今日まで | |
# sed -> jsonの改行形式に変換 | |
CAL=$(khal list --format "{title}" today today | sed -z -e "s/\n/\\\\\\\\n/g") | |
# イベントのない日は投稿せず終了 | |
if [ "${CAL}" = 'No events\\n' ] | |
then | |
echo "${CAL}" | |
exit | |
fi | |
MSG=$(printf '{"username": "今日のイベント📅", "content": "%s"}\n' "${CAL}") | |
echo "$MSG" | |
# Discord WebHock でKagolug の#random へpost | |
curl -X POST -H "Content-Type: application/json" \ | |
-d "${MSG}" \ | |
"${DISCORD_WEBHOOK}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment