reveille (2289B)
1 #!/usr/bin/env bash 2 3 readonly DAY_SECONDS=86400 4 5 # TODO: replace this constant with an API request. 6 # https://www.ssa.gov/cgi-bin/longevity.cgi 7 readonly ESTIMATED_REMAINING_YEARS=45 8 readonly ESTIMATED_REMAINING_DAYS="$(( "${ESTIMATED_REMAINING_YEARS}" * 365))" 9 10 age() { 11 local start end 12 13 start="$(date -d "$1" +%s)" 14 end="$(date -d "$2" +%s)" 15 16 echo $((("${end}" - "${start}") / "${DAY_SECONDS}")) 17 } 18 19 birthday() { 20 local year 21 local month 22 local day 23 24 year="$(pass dwrz/birth-year)" 25 month="$(pass dwrz/birth-month)" 26 day="$(pass dwrz/birth-day)" 27 28 echo "${year}-${month}-${day}" 29 } 30 31 draft_message() { 32 email="/tmp/reveille-$(date +%s)" 33 current_age_days="$(age "$(birthday)" "$(date '+%Y-%m-%d')" )" 34 35 cat > "$email" << EOF 36 37 You have been on Earth, in this form, for $(numfmt --grouping \ 38 "${current_age_days}") days. 39 40 You have $(numfmt --grouping ${ESTIMATED_REMAINING_DAYS}) days left. \ 41 You might have more. 42 Or today could be your last day. 43 44 Make the most of the time you have. 45 46 Remember: 47 - If you have the essentials, you have the foundations for happiness. 48 - You are surrounded by people largely like youself: imperfect and 49 evanescent. Treasure them; they, like you, may not be around for much 50 longer. 51 - People have invested in you -- with time, energy, money, lessons, and 52 perspectives. Living things have given their life to sustain you. You 53 owe the world the best version of yourself. 54 - The ego does not always act in its best interests. 55 - Beware the sirens' song. 56 - No plan ever survives initial contact with reality. 57 - Fatigue does not equal fitness. 58 - Slow is smooth, and smooth is fast. 59 60 QOTD: 61 62 $(wisdom | fold --spaces --width 72) 63 64 每日中文: 65 $(shuf -n 8 "${HOME}"/projects/chinese/vocabulary.csv | sort) 66 67 Sunrise & Sunset: 68 Los Angeles $(sun -c 34.052235,-118.243683 -f 15:04 -z America/Los_Angeles) 69 New York City $(sun -c 40.730610,-73.935242 -f 15:04 -z America/New_York) 70 Napoli $(sun -c 40.853294,14.305573 -f 15:04 -z Europe/Rome) 71 上海 $(sun -c 31.224361,121.469170 -f 15:04 -z Asia/Shanghai) 72 Sydney $(sun -c -33.865143,151.209900 -f 15:04 -z Australia/Sydney) 73 74 EOF 75 76 echo "${email}" 77 } 78 79 main() { 80 mail -r "$(pass dwrz/email)" \ 81 -s "$(date '+%Y-%m-%d %j/365 %W/52 %u/7')" \ 82 "$(pass dwrz/email)" < "$(draft_message)" 83 } 84 85 main "$@"