From 76fedd6fcaf478b52c3190657aa60c571bab50aa Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Tue, 2 Feb 2016 13:05:42 +0000 Subject: [PATCH 1/5] Renamed get_ms_data -> get_snds_data --- README.md | 2 +- get_ms_data => get_snds_data | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename get_ms_data => get_snds_data (100%) diff --git a/README.md b/README.md index e95f991..f335fa1 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,4 @@ See https://postmaster.live.com/snds/ for details. Utilities --------- -get_ms_data - Gets the two current data files for your SNDS account. +get_snds_data - Gets the two current data files for your SNDS account. diff --git a/get_ms_data b/get_snds_data similarity index 100% rename from get_ms_data rename to get_snds_data From d878aa32ec2ac2aa1b09594c4d79c164539c09ba Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Tue, 2 Feb 2016 13:15:38 +0000 Subject: [PATCH 2/5] Add email utility --- README.md | 1 + email_snds_data | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 email_snds_data diff --git a/README.md b/README.md index f335fa1..09ccafb 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,4 @@ Utilities --------- get_snds_data - Gets the two current data files for your SNDS account. +email_snds_data - Get the data files and send them to an email address. diff --git a/email_snds_data b/email_snds_data new file mode 100755 index 0000000..af5c48f --- /dev/null +++ b/email_snds_data @@ -0,0 +1,51 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use 5.010; + +use LWP::UserAgent; +use Email::Stuffer; + +my $to = shift || die "No email address given\n"; + +my @urls = qw[ + https://postmaster.live.com/snds/data.aspx + https://postmaster.live.com/snds/ipStatus.aspx +]; +my $key = shift || $ENV{SNDS_KEY}; + +die "No SNDS key given\n" unless defined $key; + +my $ua = LWP::UserAgent->new; + +my $email = Email::Stuffer->new + ->to($to) + ->subject('SDNS Data') + ->from('postmaster@mag-sol.com') + ->text_body('Here is your SNDS data'); + +foreach (@urls) { + if (my $file = get_url($ua, $_, $key)) { + $email->attach_file($file); + } +} + +$email->send_or_die; + +sub get_url { + my ($ua, $url, $key) = @_; + + my $resp = $ua->get("$url?key=$key"); + my $data = $resp->content; + unless (length $data) { + warn "No data for $url\n"; + return; + } + + my $file = $resp->filename; + open my $out_fh, '>', $file or die "$file: $!"; + print $out_fh $data; + + return $file; +} From e9f73c19d2d04d76168b7688c22c6ff5c6ab960a Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Tue, 2 Feb 2016 13:36:22 +0000 Subject: [PATCH 3/5] Reformat README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09ccafb..f4c3d0b 100644 --- a/README.md +++ b/README.md @@ -8,5 +8,5 @@ See https://postmaster.live.com/snds/ for details. Utilities --------- -get_snds_data - Gets the two current data files for your SNDS account. -email_snds_data - Get the data files and send them to an email address. +* get_snds_data - Gets the two current data files for your SNDS account. +* email_snds_data - Get the data files and send them to an email address. From def406ec3badf71ede396506f5cf7d3b33edca71 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Wed, 3 Feb 2016 10:25:27 +0000 Subject: [PATCH 4/5] Add body text for body data. --- email_snds_data | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/email_snds_data b/email_snds_data index af5c48f..6d733b4 100755 --- a/email_snds_data +++ b/email_snds_data @@ -22,15 +22,19 @@ my $ua = LWP::UserAgent->new; my $email = Email::Stuffer->new ->to($to) ->subject('SDNS Data') - ->from('postmaster@mag-sol.com') - ->text_body('Here is your SNDS data'); + ->from('postmaster@mag-sol.com'); + +my $body = 'Here is your SNDS data'; foreach (@urls) { if (my $file = get_url($ua, $_, $key)) { $email->attach_file($file); + } else { + $body .= "\n\nNo data from $_."; } } +$email->text_body($body); $email->send_or_die; sub get_url { @@ -39,7 +43,7 @@ sub get_url { my $resp = $ua->get("$url?key=$key"); my $data = $resp->content; unless (length $data) { - warn "No data for $url\n"; + warn "No data from $url\n"; return; } From 7388c85064aa392b72b906d7e681180c181af0b3 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Wed, 3 Feb 2016 10:26:22 +0000 Subject: [PATCH 5/5] Added .gitignore. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..afed073 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.csv