Skip to content

Instantly share code, notes, and snippets.

@necrobious
Last active August 29, 2015 14:02
Show Gist options
  • Save necrobious/ed00120ff60478839154 to your computer and use it in GitHub Desktop.
Save necrobious/ed00120ff60478839154 to your computer and use it in GitHub Desktop.
Scrape all of your instagram's standard size photos into an SQLite3 database.
#!/bin/bash
if [ "$#" -ne 1 ]; then
PROG=$(basename $0)
echo "Usage: $PROG <instagram_user_id>"
exit 1
fi
IGUSER=$1
DBFILE="ig_$IGUSER.sqlite3"
CLIENTID=YOUR_CLIENT_ID
NEXT="https://api.instagram.com/v1/users/$IGUSER/media/recent?client_id=$CLIENTID"
echo "CREATE TABLE IF NOT EXISTS images (ig_id TEXT PRIMARY KEY, url TEXT);" | sqlite3 -echo $DBFILE;
until [ -z "$NEXT" ]; do
PAGE=$(curl -s $NEXT | jq '{"next": .pagination.next_url, "images": [.data[] | {"id": .id, "url": .images.standard_resolution.url}]}');
echo -n $PAGE | jq -r '.images[] | @text "INSERT OR IGNORE INTO images VALUES ('\''\(.id)'\'', '\''\(.url)'\'');"' | sqlite3 -echo $DBFILE;
NEXT=$(echo -n $PAGE | jq -r 'if .next == null then "" else .next end');
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment