#!/usr/bin/perl -w use lib '/home2/ucsevsix/perl5/lib/perl5'; use MIME::Lite; use LWP::UserAgent; use POSIX; ### use Text::Wrap; ### July 10, 2023 no ore wrap of
text
no warnings 'uninitialized';
# use LWP::Simple;
# use CGI qw(:standard);
# use LWP::Simple qw(get);
# use LWP::Simple qw(!head);
# use HTML::Parse;
# use HTML::FormatText;
# use CGI::Carp qw(warningsToBrowser fatalsToBrowser); # may need this when testing
# use strict;
$ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin';
# Print MIME type
# print "Content-type: text/html\n\n";
# if you use special char @, $, % inside double-quoted string, precede them with backslash (\)
# PERL Forms Parsing Code if Needed
# my %FORM;
# foreach my $field (param()) {
# $FORM{$field} = param($field);
# }
# SAMPLE SPLIT STRING INTO ARRAY
# @personal = split(/:/, $info);
# @personal = split(/\n/, $info); "new line" split for the html code read into string
# IMPORTANT \n if you use LWP::Simple get(), \r if you use LWP::UserAgent get()
# Design Concepts for Dashboard SMS PERL Program
# An SMS single character code drives the desired SMS response to Bruce
# areafc_dashboard_sms.pl
# a area forecast discussion
# d full dashboard
# s stocks
# f full finance
# g golf scores
# --------- begin weather area forecast discussion code ---------------- #
# new URL as of January 2 2013
# https://forecast.weather.gov/product.php?site=NWS&issuedby=MTR&product=AFD&format=txt&version=1&glossary=0
# If use LWP::Simple; the code look like this
# $weatherURL[$k] = "https://mobile.weather.gov/ob.php?obvar=".$weatherob[$k];
# $contentWEATHER[$k] = get($weatherURL[$k]);
# @WEATHERhtml = split(/\n/,$contentWEATHER[$k]); IMPORTANT \n if you use LWP::Simple get(), \r if you use LWP::UserAgent get() or maybe not
my $ua = new LWP::UserAgent;
$ua->timeout(120);
my $weatherURL = "https://forecast.weather.gov/product.php?site=NWS&issuedby=MTR&product=AFD&format=txt&version=1&glossary=0";
my $request = new HTTP::Request('GET', $weatherURL);
my $response = $ua->request($request);
my $content = $response->content();
@WEATHERhtml = split(/\n/,$content);
foreach $a (0..$#WEATHERhtml) {
if ($WEATHERhtml[$a] =~ /AFDMTR/) {
$beginrowafd = $a;
last; # new code to stop loop here and speed up processing
}
}
foreach (0..$beginrowafd) {
shift(@WEATHERhtml);
}
### new code 4.8.2012 ### replace backtick with apostrophe in Area Discussion
foreach $c (0..$#WEATHERhtml) {
if ($WEATHERhtml[$c] =~ /sanfrancisco/) {
$endingrowafd = $c;
}
# backtick replace code #
$WEATHERhtml[$c] =~ s/`/'/g;
}
foreach ($endingrowafd-2..$#WEATHERhtml) {
pop(@WEATHERhtml);
}
## Adding new code to allow better formatting of HTML Emails, Tags Above, Body Stuff, Tags Below
$malebody = "";
$htmltagsabove = "";
$malebody = $malebody.$htmltagsabove;
$now_string = strftime "%a %b %e %I:%M %P", localtime(time-3600);
$malebody = $malebody."".$now_string."
\r\n";
### --- July 10, 2023 removing the text-wrap columns --- ###
## --- trying to wrap AFD array --- ##
### $Text::Wrap::columns = 28;
### print "";
## $malebody = $malebody."
"."".
## join(" ",@WEATHERhtml).""; ### Does not look good in gmail ##
$afd = join(" ",@WEATHERhtml);
## --- $malebody = $malebody."Hey Mon No Problem"; --- ## testing, it works
### July 10 2023 no more wrap ----- $malebody = $malebody."".wrap('', '', $afd).""; ###
$malebody = $malebody.$afd;
$htmltagsbelow = "";
$malebody = $malebody.$htmltagsbelow;
$rsvp_subject = "Weather Area FC Discussion\r\n";
# --- EMAIL CODE TO SEND THE SUBJECT AND BODY OF EMAIL USING MIME:lite --- #
# Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From => 'BFD CEO ',
To => 'calbear76@gmail.com, b262d@yahoo.com',
Subject => $rsvp_subject,
Type => 'multipart/mixed'
);
# --- Add the body text -- Add Body Text to email --- #
$msg->attach(
# Type => 'TEXT',
Type => 'text/html', # is this the magic bullet for sending HTML #
Data => $malebody
);
# --- Now Email Magic Bullet for Sending the Message --- #
### Original code as July 23, 2022 a.m. ###
# MIME::Lite->send('sendmail', "/usr/sbin/sendmail -t -i"); #
### --- July 30, 2022 code change using -f option from CPAN Doc - THIS WORKS --- ###
MIME::Lite->send('sendmail', "/usr/sbin/sendmail -t -i -fceo\@uc76bd.com");
$msg->send;
exit 0;
sub dienice {
my($errmsg) = @_;
print "Error\n";
print "$errmsg\n";
exit;
}