Skip to content

Instantly share code, notes, and snippets.

@pzi
Last active February 7, 2025 03:15
Show Gist options
  • Save pzi/4ed21cd02979cafcba975a0a61d78b72 to your computer and use it in GitHub Desktop.
Save pzi/4ed21cd02979cafcba975a0a61d78b72 to your computer and use it in GitHub Desktop.
Bash script that extracts the latest Instagram post of the RestoreNorthbridge IG account, downsamples it and sends it to a teams channel via email.
#! /bin/bash
# Instagram Details
LATEST_RESTORE_POST_URL="https://www.instagram.com/graphql/query/?query_id=17888483320059182&id=1535102564&first=1"
POST_THUMB_JQ=".data.user.edge_owner_to_timeline_media.edges[0].node.thumbnail_src"
# Mailgun Details
API_KEY="NO_API_KEY_SET"
DOMAIN="NO_DOMAIN_SET"
# E-Mail Details
FROM="Re Store Lunch <[email protected]>"
SUBJECT="Today's menu - $(date '+%A, %d %B %Y')"
EXPIRY_TIME=$(date -v+2H -u "+%a, %d %b %Y %H:%M:%S GMT")
TEAMS_EMAIL="Re Store Lunch <[email protected]>"
# SLACK_EMAIL="Re Store Lunch <[email protected]>"
BCC_EMAIL="Example <[email protected]"
CONTROL_EMAIL="Example <[email protected]"
TEXT="This e-mail contains the latest Instagram post of the @restorenorthbridge account."
PHOTO_SRC="$(curl -s "$LATEST_RESTORE_POST_URL" | /usr/local/bin/jq --raw-output "$POST_THUMB_JQ")"
printf "Found photo source:\n${PHOTO_SRC}\n"
STRIPPED_NAME=$(basename ${PHOTO_SRC%\?*})
printf "\nDownloading...\n"
curl -sS -o $STRIPPED_NAME "$PHOTO_SRC"
OUTPUT_IMAGE="ReStore_Post_$(date '+%d_%m_%Y').jpg"
printf "\nConverting original file to JPG...\n"
sips -s format jpeg --setProperty formatOptions 50 --resampleWidth 640 "$STRIPPED_NAME" --out "$OUTPUT_IMAGE"
printf "\nSending E-Mail...\n"
curl -s --user "api:$API_KEY" \
https://api.mailgun.net/v3/$DOMAIN/messages \
-F from="$FROM" \
-F to="$TEAMS_EMAIL" \
-F bcc="$CONTROL_EMAIL" \
-F bcc="$BCC_EMAIL" \
-F subject="$SUBJECT" \
-F "h:Expiry-Date=$EXPIRY_TIME" \
-F text="$TEXT" \
-F inline=@"$OUTPUT_IMAGE" \
-F attachment=@"$OUTPUT_IMAGE" \
--form-string html="<html><body><img src=\"cid:${OUTPUT_IMAGE}\"/></body></html>"
printf "\nOpening converted image: ${OUTPUT_IMAGE}\n"
open $OUTPUT_IMAGE
printf "\nRemoving original file: ${STRIPPED_NAME}\n"
rm $STRIPPED_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment