Skip to content

Instantly share code, notes, and snippets.

@yuchan
Created September 30, 2012 05:13
Show Gist options
  • Save yuchan/3805932 to your computer and use it in GitHub Desktop.
Save yuchan/3805932 to your computer and use it in GitHub Desktop.
tag feed of Pinboard.
#! /usr/bin/env perl
use strict;
use warnings;
use Encode;
use Data::Dumper;
use XML::FeedPP;
use File::Copy;
use File::Spec;
use diagnostics;
sub mailsend
{
my($from, $to, $subject, $msg) = @_;
my $sendmail = '/usr/sbin/sendmail'; # sendmail command pass.
open(SDML,"| $sendmail -t -i") || die 'sendmail error';
# output of mail header
print SDML "From: $from\n";
print SDML "To: $to\n";
print SDML "Subject: $subject\n";
print SDML "Content-Transfer-Encoding: 7bit\n";
print SDML "Content-Type: text/plain;\n\n";
# output of mail
print SDML "$msg";
# close sendmail cmd.
close(SDML);
}
sub alreadyexist
{
my ($data, $firstline) = @_;
if(!$data || !$firstline){
return 0;
}
#print length($data).':'.length($firstline);
if($firstline eq $data){
#print 'same\n';
return 1;
}
return 0;
}
my $from = 'news@example.com'; # 送信元メールアドレス
my $to = 'you@example.com'; # あて先メールアドレス
my $subject = 'news headlines'; # メールの件名
my $home = $ENV{'HOME'};
my $feed = XML::FeedPP->new( 'http://feeds.pinboard.in/rss/t:webservice' );#t:webservice
my $dir = $ENV{'HOME'}."/src/";
my $firstdata;
open(RH, '<', $dir."l.txt") or die "die at open l.txt $!";
while(my $line = <RH>) {
$firstdata = $line;
last;
}
close(RH);
open(FH, '>', $dir."l.txt") or die "die at l.txt $!";
my $countup=0;
my $msg;
foreach my $item ($feed->get_item()) {
my $data = 'URL: '.$item->link()."\n";
my $exist = alreadyexist($data, $firstdata);
if($exist == 1){
print FH $firstdata;
last;
}
$msg .= $data;
$msg .= 'Title: '. $item->title(). "\n";
if($item->description()){
$msg .= 'DESC: '. $item->description(). "\n";
}
$msg .= '----------'. "\n";
if($countup == 0){
print FH $msg;
}
$countup++;
}
if($msg && length($msg) > 0){
mailsend($from, $to, $subject, $msg);
}
close(FH);
@yuchan
Copy link
Author

yuchan commented Sep 30, 2012

I read only first in a readline loop and broke.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment