Skip to content

Instantly share code, notes, and snippets.

@Sonictherocketman
Created April 3, 2021 20:28
Show Gist options
  • Save Sonictherocketman/8504244c5c916f41dc7815e28f297b86 to your computer and use it in GitHub Desktop.
Save Sonictherocketman/8504244c5c916f41dc7815e28f297b86 to your computer and use it in GitHub Desktop.
A personalized weekly Pinboard-based newsletter of pages you said you wanted to read.
set -e;
# Creates a simple email message containing links from your recent Pinboard
# bookmarks that are marked as "to read".
echo "[$(date)] Beginning pinboard weekly summary...";
CREDS="user:token"
TO="$(date -u +'%Y-%m-%dT%H:%M:%SZ')"
FROM=$(date --date="$FROM -7 day" +'%Y-%m-%dT%H:%M:%SZ')
URL="https://api.pinboard.in/v1/posts/all?auth_token=$CREDS&count=100&format=json&fromdt=$FROM&todt=$TO"
TOREAD=$(curl -s $URL | jq -c -r '.[] | select(.toread | contains("yes")) | @base64');
REPORT="$(date -I).html"
getmailbody() {
echo "<h1>Weekly Pinboard Reading List</h1>";
echo "<h3>For the week of $(date -I)</h3>"
echo "<p>For your use, here's a selection of articles you said you wanted to read.</p>"
echo "<ul>"
echo "$TOREAD" | while read ROW; do
# Solution from
# https://www.starkandwayne.com/blog/bash-for-loop-over-json-array-using-jq/
_jq() {
echo ${ROW} | base64 --decode | jq -r ${1}
}
if [ -n "$ROW" ]; then
NAME="$(_jq '.description')"
DESC="$(_jq '.extended')"
LINK="$(_jq '.href')"
NAME=${NAME:=$LINK}
DESC=${DESC:="<i>no description</i>"}
echo "<li><a href='$LINK'>$NAME</a><p>$DESC</p></li>";
fi
done;
echo "</ul>"
}
if [ -n "$TOREAD" ]; then
echo "$(getmailbody)" | mail \
-a "Content-type: text/html" \
-s "Weekly Pinboard Summary" <email address>
else
echo "Nothing to report. Done."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment