#! /usr/local/bin/perl

# 6.837
# Created by Justin Legakis (legakis@graphics.lcs.mit.edu) for Fall 1996
# Modified by Jon Levene (jslevene@graphics) for Fall 1997

# For each student that does not have a thumbnail picture, attempt
# to grab their full-sized picture from their given URL, and store
# it in ../pictures_tmp

$picpath="../thumbnails";
$scriptspath="../scripts";

chdir "../data/";

opendir(THISDIR, ".");
@allfiles = grep(!/^\.\.?|(.*)\.html.?|(.*)~/, readdir(THISDIR));
closedir(THISDIR);


foreach $file (@allfiles) {

	open(FILE, "$file") || die "can't open file $file";
	@lines = <FILE>;
	(@email[0]) = @lines[4] =~ /^email: (.*)$/;
	(@picture[0]) = @lines[26] =~ /^picture: (.*)$/;

	($thumbtitle, $domain) = split(/\@/, @email[0]);


	$command = "$scriptspath/6837-grabfile @picture[0] $picpath/$thumbtitle.gif";

	print " Grabbing picture: $email[0].gif\n";
	
	system($command);


}

