Fetching instagram posts into Hugo

I have been trying to build something that fetched my photos from instagram to publish them with Hugo. Since I couldn’t make much progress with GoLang and instagram’s API, I used a different approach with IFTTT fetching the last photo and uploading to Dropbox. The script below takes every photo found in that folder, moves it to Hugo and configures the necessary page bundle and .Resources.

Hope it’s useful for someone else:

#! /bin/bash

# IFTTT configuration for file name: {{CreatedAt}}-{{Caption}}
# IFTTT configuration for Dropbox Folder: IFTTT/Instagram

# Configure the path to your dropbox
DROPBOX="/Users/brunoamaral/Dropbox/ifttt/Instagram/"

# Configure the path to the directory in your blog where you want to save the Instagram Photos
INSTAGRAMS="/Users/brunoamaral/Labs/Digital-Insanity/content/instagrams/"

cd $DROPBOX;
for FILE in *.jpg
do
	echo "$FILE"
	rawpostdate=$(echo "$FILE" | awk -F" at" '{print $1}')
	postdate=$(date -jf '%B %d, %Y' "$rawpostdate" '+%Y-%m-%d')
	rawposttime=$(echo "$FILE" | awk -F"at " '{print $2}' | awk -F"-" '{print $1}')
	posttime=$(date -jf '%l:%M%p' "$rawposttime" '+%R' )
	datetime=("$postdate"T"$posttime":00Z)
	posttitle=$(echo "$FILE" | awk -F"-" '{print $2}' | awk -F".jpg" '{print $1}' )

	DESTINATION=("$INSTAGRAMS$postdate-${posttitle//#}")

	mkdir "$DESTINATION";
	mv "$FILE" "$DESTINATION/$postdate-${posttitle//#}.jpg"

	# This is the default frontmatter for Instagram posts. You will want to double check the settings to fit your taste.
	printf '%s\n' '---'  'categories: ["instagram"]'  "date: $datetime"  'description: ""'  'draft: false'  'resources:' "  - src: $postdate-${posttitle//#}.jpg" '    name: "header"'  'layout: instagram' 'slug:'  'stories:'  'subtitle:'  "title: $posttitle"  '---' '' > "$DESTINATION"/index.md ; 

	echo 'title:' $posttitle
	echo 'date:' $postdate
	echo 'time:' $posttime;

done
4 Likes