#!/bin/bash
# February 23, 2017

# downloads images from URLs and renames them to certain names
# parameter 1: csv file with names and URLs

# to get json code of listingids and first images:
# select json_agg(t) from (select listingid,images[1] from listing) t

# example file (first line gets ignored, can be used for headers/comments/etc):
#
# name,url
# image1,http://bla.com/bla.jpg
# image2,http://bla.com/bla2.jpg

if [ $# -ne 1 ]; then
	echo "usage: $0 <file_name>"
	exit 1
fi

firstline=0;
while IFS=, read -ra arr; do
    if [[ $firstline -eq 0 ]]; then
		firstline=1
    else
		curl ${arr[1]} > ${arr[0]}.jpg
    fi
done < $1
