Last active
May 7, 2021 18:38
-
-
Save thcipriani/9ed54c9d87ff5919f96596b678c855cc 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
#!/usr/bin/env bash | |
# | |
# Word of the Day! | |
# | |
# Get m-w.com's top word lookup of however long... | |
# | |
# USAGE: | |
# | |
# (/^ヮ^)/*:・゚✧ date -Is | |
# 2021-01-06T16:38:27-07:00 | |
# (/^ヮ^)/*:・゚✧ ./word-of-the-day.sh | |
# WotD: "insurrection" | |
# | |
# Copyright Tyler Cipriani <[email protected]> 2020 | |
# License: GPLv3 | |
set -euo pipefail | |
WORD= | |
WOTD="${XDG_CACHE_HOME:-"$HOME"}/.wotd" | |
MW_POPULAR_JSON="https://www.merriam-webster.com/lapi/v1/mwol-mp/get-lookups-data-homepage" | |
OLD=1 | |
if [[ -f "$WOTD" ]]; then | |
CTIME=$(stat -c '%X' "$WOTD") | |
NOW=$(date +%s) | |
ONE_HOUR=3600 | |
OLD=$(( (NOW - CTIME) > ONE_HOUR )) | |
fi | |
if (( OLD == 1 )); then | |
WORD=$(curl -s "$MW_POPULAR_JSON" | jq -r '.data.words[0]') | |
printf 'WotD: "%s"\n' "$WORD" > "$WOTD" | |
fi | |
cat "$WOTD" |
Author
thcipriani
commented
Jan 13, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment