#!/usr/bin/perl
use strict;
#use AWS::S3;
use Data::Show;
use MIME::Lite;
use DateTime;
use Path::Tiny;

my $dt = DateTime->now(time_zone => 'America/Chicago');
my $url = 'http://clm.dmadelivers.com/api/customer/report/export_missing_opstatus?key=b59597f8-42f5-48b9-8cbb-9a60348821c2';
my $file = 'dma_missing_opstatus.created.' . $dt->ymd('') . $dt->hms('') . '.xls';
my $subject = 'CLM Missing Operating Status Created: ' . $dt->ymd('-') . ' ' . $dt->hms(':');
if($ARGV[0] eq 'updated'){
	$url .= '&updated=1';
	$file = 'dma_missing_opstatus.updated.' . $dt->ymd('') . $dt->hms('') . '.xls';
	$subject = 'CLM Missing Operating Status Updated: ' . $dt->ymd('-') . ' ' . $dt->hms(':')
}

my $dir = '/tmp/';

my $cmd = '/usr/bin/wget -P ' . $dir  . ' --content-disposition "' . $url . '" 2>&1';
my @res = `$cmd`;
unlink('/tmp/' . $file . '.1');




my $msg = MIME::Lite->new(
	From     => 'root@dmadelivers.com',
	Cc => 'dma@ace4it.com',
	# To => 'dma@ace4it.com',
	To => 'opfftp@dmadelivers.com',
	# To => 'matt.kot@dmadelivers.com',
	# Cc => 'jim.szatkowski@dmadelivers.com',
	# Bcc => 'dma@ace4it.com',
    Subject  => $subject,
	Type => 'multipart/mixed'
);
	$msg->attach(
		Type     => 'text/plain',
		Data => ' '
	);
$msg->attach(
	# Type     => 'text/plain',
	# Type     => 'application/octet-stream',
	Type => 'application/vnd.ms-excel',
	Path => $dir . $file
);
$msg->send;
