Last active
August 29, 2015 14:02
-
-
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.
This file contains hidden or 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
#!/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