Skip to content

Instantly share code, notes, and snippets.

@mosladil
Created December 1, 2014 13:30
Show Gist options
  • Save mosladil/0be954e27c7f696f0ad7 to your computer and use it in GitHub Desktop.
Save mosladil/0be954e27c7f696f0ad7 to your computer and use it in GitHub Desktop.
Agent Milan
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use encoding 'utf8';
use LWP::Simple;
use XML::RSS;
use Data::Dumper;
use Encode; #qw/encode decode/;
binmode STDIN, ":utf8";
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";
my $from = '[email protected]';
my $conference = '[email protected]';
my $url = "http://www.novinky.cz/rss/domaci";
my $rss = new XML::RSS;
my $content = get($url);
my @titulky = ();
my @clanky = ();
my @before = (
'Tradiční ranní dávka keců...',
);
my @after = (
'To je ale pěkná kravina (((:',
'OMG!',
'Sračky jako z tuzexu.',
'No to to trvalo.',
'Hurá, konečně někdo dostal rozum.',
'Zajímalo by mě, jak dlouho to bude platit.',
'Kecy kecy kecy. Jako obvykle.',
'Jen nevim jestli to je k smíchu nebo k pláči.',
'To mi mluví přímo z duše...',
'...stejně za to můžou komunisti...',
'Kam ten svět spěje?',
'Zeman by to nedovolil.',
'',
);
print "Mode: (manual|rss)? ";
my $mode = <>;
chomp($mode);
my ($to, $message, $subject);
if($mode =~ /manual/) {
print "To: ";
$to = <>;
chomp($to);
print "Subject: ";
$subject = <>;
chomp($subject);
print "Message: ";
$message = <>;
chomp($message);
} elsif ($mode =~ /rss/) {
$to = $conference;
$rss->parse($content);
#print "$rss->{'channel'}->{'title'}\n\n";
foreach my $item (@{$rss->{'items'}}) {
#next unless defined($item->{'title'}) && defined($item->{'link'});
next if($item->{'title'} =~ /video/i);
push(@clanky, $item->{'description'});
push(@titulky, $item->{'title'});
}
my $place = rand(@titulky);
$subject = $titulky[$place];
$message =
$before[int rand($#before)]. ' '.
#$clanky[int rand($#clanky)].' '.
$clanky[$place]."\n\n".
$after[int rand($#after)];
}
&sendEmail($to, $from, $subject, $message);
sub sendEmail {
my ($to, $from, $subject, $message) = @_;
my $sendmail = '/usr/lib/sendmail';
my $utf8Subject = encode('MIME-Header', $subject);
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "X-Priority: 3\n";
print MAIL "X-MSMail-Priority: Normal\n";
print MAIL "X-Mailer: Kerio Outlook Connector (Offline Edition) (7.0.0.402 B1)\n";
print MAIL "Importance: Normal\n";
#print MAIL "Message-ID: <hash\@osladil.cz>\n";
print MAIL "X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16669\n";
print MAIL "Content-Type: text/plain; charset=\"UTF-8\"\n";
print MAIL "Subject: ".$utf8Subject."\n\n";
print MAIL $message."\n";
close(MAIL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment