Last active
October 21, 2022 06:20
-
-
Save lirlia/44bdf31244ba5c3964f259bb86410437 to your computer and use it in GitHub Desktop.
This file contains 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/bash | |
## ❯ crontab -l | |
## MAILTO="" | |
## * * * * * $HOME/bin/tools/calendar/tell-schedule.sh 2 1> /dev/null 2> /tmp/calc.log | |
# 予定情報を持ってくる | |
$HOME/bin/tools/calendar/get-gcalc.sh | |
CALC_FILE=$HOME/.today_meeting | |
REMIND_TIME=${1:=1} | |
NOW_EPOCH=$(date +%s) | |
SPEAKER=Kyoko | |
OFFSET=30 | |
# オフィスでなるのを避けたいのでこのIPの時は喋らない | |
OFFICE_NW="YOUR_OFFICE_IP" | |
function isOffice() { | |
# 2つのサーバーのうちどれか一つが生きていれば動く | |
if (curl -s --fail https://checkip.amazonaws.com || curl -s --fail https://ifconfig.io) | grep "$OFFICE_NW" > /dev/null; then | |
echo 'yes' | |
else | |
echo 'no' | |
fi | |
} | |
cat $CALC_FILE | while read line; do | |
set ${line} | |
TASK_TIME=${1} | |
TASK_EPOCH=$(date -j -f "%H:%M" ${TASK_TIME} +%s) | |
TASK_NAME=${2} | |
URL=${3} | |
# タスクの時刻よりも、現在時刻+引数の時刻の方が後なら発言 | |
if [[ $NOW_EPOCH -ge $(($TASK_EPOCH - $REMIND_TIME * 60 - $OFFSET)) ]] && \ | |
[[ $NOW_EPOCH -le $(($TASK_EPOCH - $REMIND_TIME * 60 + $OFFSET)) ]]; then | |
DIFF_MIN=$((($TASK_EPOCH-$NOW_EPOCH)/60)) | |
# tell me schedules by siri | |
[[ $(isOffice) == "no" ]] && say -v $SPEAKER "${DIFF_MIN}分後、${TASK_NAME}。" | |
# open browser | |
[ "${URL}" != "" ] && open "${URL}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment