#!/usr/bin/perl -w
use Net::FTP;
use File::Copy;
use Net::SMTP;
use File::Basename;
use Email::Send::SMTP::Gmail;
use POSIX qw(strftime);
my $date = strftime("%m-%d-%y",localtime);
my $time = strftime("%I:%M:%S",localtime);
my $ftpdate = strftime("%m-%d-%y",localtime);
#PC
my $logfile = "/Users/bflieck/Documents/Wilsons_push.txt";
#mac
# my $logfile = "/Users/flieckb/Documents/Wilsons_push.txt";
my $log = ">> $logfile";
#"//10.55.11.15/
###############define all the folders in this game##############
my $PSD = "//10.55.11.15/photorepos/Partners/Wilsons/Done/";
my $JPG = "//10.55.11.15/photorepos/Partners/Wilsons/2push/";
my $repos = "//10.55.11.15/photorepos/Weekly_Product_Folders/Wilsons/";
my $reposdate = "//10.55.11.15/photorepos/Weekly_Product_Folders/Wilsons/$date/";
my $repospsddate = "//10.55.11.15/photorepos/Weekly_Product_Folders/Wilsons/$date/PSD/";
my $repostiffdate = "//10.55.11.15/photorepos/Weekly_Product_Folders/Wilsons/$date/JPEG/";
my $mybadmatch="_s.jpg";
my $badswatches= "//10.55.11.15/photorepos/Perl/Mother/Wilsons/badswatches/";
################################################################
my $current = `date +%m/%d/%Y`;
chomp $current;
chomp $date;
#############Sort the JPG's for bad swatch files
chdir( $JPG ) or warn "Cant chanage to $JPG $!";
(@upload_JPG) = glob "*";
my $upload_count_JPG = @upload_JPG;
foreach my $file (@upload_JPG) {
if ($file =~ m/$mybadmatch/is)
{
my $old = "$JPG$file";
my $new = "$badswatches";
move ($old, $new) or warn print "can't copy the badswatches $file\n";
open FILE, '>> //10.55.11.15/photorepos/Perl/Mother/Wilsons/Upload/RemovedSwatches.txt' or warn $!;
print FILE "$current\t$date\t$file\t";
print FILE "\n";
}
else
{
print "these dont have to move $file\n";
}
}
close FILE;
#get the PSD folder count
chdir( $PSD ) or warn "Cant chanage to $JPG $!";
(@PSD) = glob "*";
my $PSD_count = @PSD;
###########################################
chdir( $JPG ) or warn "Cant chdir to $JPG $!";
my(@file_list) = glob "*";
open FILE, "$log" or warn $!;
foreach my $file (@file_list){
my $filenameonly;
my $style;
my $color;
my $view;
if ($file =~qr/\A([^_]+)_([^_]+)(?:_([^_]+))?\.([^\.]+)\z/
) {
$filenameonly = $1 .'_'. $2;
$style = $1;
$color = $2;
$view = $3;
} else {
#File did not match...
next;
}
$view = '' if (!defined($view));
print FILE "$current\t$file\t$filenameonly\t$style\t$color\t$view\tWilsons\n";
}
close FILE;
#PC
my $dir ="/Users/bflieck/Documents/";
#Mac
# my $dir ="/Users/flieckb/Documents/";
chdir ($dir);
my $filetobecopied = "Wilsons_push.txt";
my $newfile = "//10.55.11.15/photorepos/Reports/Wilsons/Wilsons_push.txt";
if (copy($filetobecopied, $newfile) == 0){;
print"$date $time log error\n";
}
else
{
print "$date $time log updated\n";
}
##########################################
if (@upload_JPG > 0) {
$ftp = Net::FTP->new('******', Debug => 1);
$ftp->login('*****,'*****');
$ftp-> binary();
$ftp->cwd("GSI Images/");
chdir("GSI Images/");
if (-d "ftpdate/"){
$ftp->cwd("ftpdate/");
chdir("ftpdate/");
}
else
{
$ftp->mkdir($ftpdate, 0777);
$ftp->cwd("$ftpdate/");
chdir("$ftpdate/");
}
chdir($JPG);
foreach my $file (glob('*'))
{
$ftp->put($file) or warn $ftp->message;
sleep(0);
}
# ################################################################
chdir($repos) or warn "i cant get to repos $!";
if (-d "$reposdate") {
chdir("$reposdate")
}
else
{
mkdir($date, 0777);
chdir ($reposdate);
}
chdir($reposdate) or warn "i cant get to reposdate $!";
if (-d "$repospsddate") {
chdir("$repospsddate")
}
else
{
mkdir("PSD", 0777);
chdir ($repospsddate);
}
chdir($reposdate) or warn "i cant get to reposdate $!";
if (-d "$repostiffdate") {
chdir("$repostiffdate")
}
else
{
mkdir("JPEG", 0777);
chdir ($repostiffdate);
}
foreach $file (@PSD) {
my $old = "$PSD$file";
my $new = "$repospsddate";
move($old, $new) or warn print "Copy PSD's Failed: $!";}
foreach $file (@upload_JPG) {
my $old = "$JPG$file";
my $new = "$repostiffdate";
move($old, $new) or warn print "Copy JPEG's Failed: $!";}
################################################################
################################################################
my $subject1 = "Industrial Color Studio -- PC Wilsons Image Upload $time";
my $dllist='wilsonsimages@industrialcolor.com';
my $body ="Hello, below is a list of files that uploaded tonight.
There are $upload_count_JPG files pushing tonight\n\n";
my $spacer ="
";
my $bodylist =join "
\n", @upload_JPG;
my ($mail,$error)=Email::Send::SMTP::Gmail->new( -smtp=>'smtp.gmail.com',
-login=>'kopautomation1@industrialcolor.com',
-pass=>'*****',
-port=> '25',
-debug=> 1,
-timeout=> 1000);
$mail->send(-to=>"$dllist", -from=>"$dllist", -subject=>"$subject1", -body=>"$body $spacer $bodylist", -contenttype=>"text/html");
$mail->bye;
$ftp->close();
}
else
{
print "noimages to push tonight";
}