#!/data_systems/opt/bin/python3 """ send_raa_images.py Created 2019-04 @author: Bill Barrett """ import sys from send_cips_images import SendCipsImages SEASON = 'north_2019' VERSION = '01.10' REVISION = '05' class RaaSender: """ Send RAA message """ def __init__(self): """ """ # send_raa_images.pl # Author: Bill Barrett # use Mail::Sender; # The following should be updated on an as needed basis # my $season = "north_2019"; # my $version = "01.10"; # my $revision = "05"; # If a first argument was specified it should be a date to override the current data # my ($year, $yday); # if( scalar( @ARGV ) > 0 ) #{ # $year = int($ARGV[0] / 1000); # $yday = $ARGV[0] - ($year * 1000); # print "Using specified date: $ARGV[0] (yyyyddd) year: $year day of year: $yday\n"; #} else { # Get the date from the system # Ignore all the variables returned by gmtime other than year and day of year, [5, 7] # Definitive data is five days in arrears (86400 seconds per day) # my $five_day_offset = 5 * 86400; # ($year, $yday) = (gmtime( time - $five_day_offset))[5, 7]; # $year += 1900; # printf "Getting files for: year: %4d day of year: %3d\n", $year, $yday; #} # Get the files to be attached # my $path = "/aim/data/cips/$season/raa/level_2b/ver_$version/rev_$revision"; # my $png_file_pattern = sprintf("$path/cips_raa_2b_orbit_?????_%4d-%03d_v${version}_r${revision}.png", $year, $yday); # #my @png_files; # my $png_file_count = 0; # my $subject = ""; # # do #{ # print "searching for files matching: $png_file_pattern\n"; # @png_files = glob("$png_file_pattern"); # $png_file_count = scalar(@png_files); # print "number of matching png files: $png_file_count\n"; # # open(MAIL, "|/bin/mailx -t"); # print MAIL "To: james.craft\@lasp.colorado.edu, william.barrett\@lasp.colorado.edu\n"; # if ($png_file_count > 0) # { # $subject = sprintf("RAA for %4d-%03d has completed", $year, $yday); # print MAIL "Subject: ${subject}.\n\n"; # print MAIL "${subject}. Preparing to send ...\n"; # close(MAIL); # } else { # $subject = sprintf("RAA for %4d-%03d has NOT YET completed", $year, $yday); # print MAIL "Subject: ${subject}.\n\n"; # print MAIL "${subject}. Waiting for one hour\n"; # close(MAIL); # sleep(3600); # } #} while ($png_file_count <= 0); # # If a second argument was specified it is additional text for the subject and message # my $extra_text = scalar( @ARGV ) > 1 ? $ARGV[1]." " : ""; # print "extra text: ${extra_text}\n"; #$subject = sprintf("${extra_text}RAA level 2b images for %d-%03d", $year, $yday); # my $from = "aimpi\@lasp.colorado.edu"; # my $to = "cora.randall\@lasp.colorado.edu\n"; # my $to = "james.craft\@lasp.colorado.edu, william.barrett\@lasp.colorado.edu\n"; # my $cc = "james.craft\@lasp.colorado.edu, lumpe\@cpi.com, william.barrett\@lasp.colorado.edu, jcar\@vt.edu\n"; # my $cc = "jvcraft87\@gmail.com, william.barrett\@lasp.colorado.edu"; # my $cc = "james.craft\@lasp.colorado.edu, william.barrett\@lasp.colorado.edu"; # my $cc = ""; #$message = sprintf("${extra_text}RAA level 2b for %d-%03d", $year, $yday); # #$sender = new Mail::Sender{smtp => 'localhost', from => $from, multipart => 'Mixed', msg => $message, }; #$sender->OpenMultipart({ # from => $from, # to => $to, # cc => $cc, # subject => $message, # msg => $message, # ctype => "text/html", # encoding => "7bit" #}) or die $Mail::Sender::Error,"\n"; # # print "Attaching $png_file_count files and sending $message\n"; #$sender->Part({ # ctype => 'text/html', # msg => $message }); # # foreach (@png_files) #{ # print "Adding $_\n"; # $sender->Attach({dddddd: # description => 'aimsds raa png', # ctype => 'image/png', # encoding => 'base64', # disposition => "inline; filename=$_;\r\nContent-ID: ", # file => $_}); #} # printf("Preparing to close and send RAA level 2b images for %d-%03d\n", $year, $yday); # #$sender->Close or die $Mail::Sender::Error,"\n"; # exit; if __name__ == "__main__": """ In the operational directory this is executed from the shell script via the following lines from 'create_cips_vetted_files_metadata_db.sh' base_dir="/export/home/aimpi" create_cips_vetted_files_metadata_db.py ${base_dir}/staging/vetted_files_metadata.db Arguments ---------- argv[1] : str the database file to create """ SEND_CIPS_IMAGES = SendCipsImages(sys.argv) SEARCH_DIRECTORY = SEND_CIPS_IMAGES.get_search_directory(SEASON, VERSION, REVISION, is_raa=True) print(SEARCH_DIRECTORY)