#! /usr/local/bin/perl

# 6.837
# Created by Justin Legakis (legakis@graphics.lcs.mit.edu) for Fall 1996

require "ctime.pl";


$update = &ctime(time);

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

$picpath="/pub/www/6.837/f96/pictures_tmp";
$thumbpath="/pub/www/6.837/f96/thumbnails";
$scriptspath="/pub/www/6.837/f96/scripts";

chdir "/pub/www/6.837/f96/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]);
	$suffix = "_small.gif";
	$thumbtitle = "$thumbtitle$suffix";

	if (!-e "$thumbpath/$thumbtitle") {

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

#		print "Command: $command\n";
		print "Grabbing picture: $email[0].gif\n";

		system($command);

#		chmod 0644, "$thumbpath/$thumbtitle"

 }
}

