¦½¾µAܾ®ìÉâèª èAüPªKvB
ÅßÌuOÉÍAe·éÆ©®IÉcCb^[ÉLÌeîñð��ÄêéàÌà éªA»êÉεÄ��È��êÉg¦ »¤¾B
ܽARSS Reader Æ Twitter ̼û©é̪Ê|AÆ��¤êÍ Twitter ð RSS [_[ãíèÉg¤AÆ��¤prà è¤éB
½¾A³»fɷ�~ÄøpµÄµÜ¤ï¿½}ÆÉÈéÌÅA¿åÁÆâèª é©àµêÈ��ªB
#!/usr/bin/perl
use strict;
use utf8;
use Encode::JP;
require LWP::UserAgent;
use XML::RSS::Parser;
use Net::Twitter;
my $ua = LWP::UserAgent->new;
my $rss_p = XML::RSS::Parser->new;
# êt@CÇÝoµ
# [U[¼<>pX[h<>^Cv<>RSSÌURL<>TCg^Cg
# Æ��¤®
my $data_file = 'data.txt';
open DATA, $data_file;
flock DATA, 1;
while (my $rss = <DATA>) {
# Ú
$rss =~ s/(?:\r\n?|\n)$//;
next if $rss =~ /^#/; # Rgsͳ
my @rss_items = split /<>/, $rss;
# RSS ÇÝÝ
my $response = $ua->get($rss_items[3]);
$response->is_success or next;
my $rss_data = $response->content;
# RSS Ìp[X
my @articles;
if ($rss_items[2] eq 'type1') {
@articles = parser_type1($rss_p, $rss_data);
} else if ($rss_items[2] eq 'type2') {
@articles = parser_type2($rss_p, $rss_data);
}
# type3 È~àKvÉ��ÄLq
my $tw = Net::Twitter->new(traits => [qw/API::REST/],
username => $rss_items[0],
password => $rss_items[1]);
foreach my $ar_article (@articles) {
my @article = @$ar_article;
my $message = "${article[0]} (${rss_items[4]}) ${article[1]}";
print STDERR Encode::encode('utf-8', "${message}...");
# Twitter Ée
my $result = $tw->update($message);
print STDERR "done.\n";
sleep 30;
}
}
close DATA;
sub parser_type1
{
my ($rss_p, $rss_data) = @_;
my @articles = ();
my $rss_feed = $rss_p->parse_string($rss_data);
foreach my $item ($rss_feed->query('/channel/item')) {
my $dt_title = $item->query('title')->text_content;
my $dt_link = $item->query('link')->text_content;
push @articles, [ $dt_title, $dt_link ];
}
return @articles;
}
sub parser_type2
{
# ÊÌ^CvÌRSSp[T[ðLq
}
1;
Twitter ÆÌC^[tF[XÉÍ
Net::Twitter
Æ��¤W
[ (CPAN ©çüèÅ«é) ðp��½ªAÙ©ÌW
[à éµAR}hCÅ curl
ðÄÑoµÄàæ��BThings Every Developer Should Know
8) A command line is all you need to use the Twitter API
http://apiwiki.twitter.com/Things-Every-Developer-Should-Know#8AcommandlineisallyouneedtousetheTwitterAPInbsp
ܽA[vÌÅãÅ
sleep 30
ðµÄ��éªA�}êÍ Twitter Ì[g��ÀÖÌÎÅ éBRate limiting1AJEgÉ«A1ÔÉ150ñÜÅAÂÜè24bÉ1ñÜÅÆ��¤ï¿½ï¿½Àª éÌÅAµ½ßÉA30bÔX[vµÄ��éB
http://apiwiki.twitter.com/Rate-limiting
OqÌÆ�NèA�}ÌR[hÉÍ��©âèª èAüPÌKvª éB
ܸARSS ÌÇÝÝÉ��»¯·é�}ƪ éB
��»¯·éÆ»êÈ~·ï¿½~Ä��»¯µÄµÜ¤æ¤¾B
�LöÍܾæ��µÄ��È��B
È�NA�}ÌâèÍ PHP ůlÌR[hðÆ����È��ÌÅAPÉ Perl ÅÌGR[fBOÌÌâèB
ܽA140Ì����Àðl��µÄ��È��ÌÅA»Ì��ðI[o[µÄ��éêÉÍG[ðN�}µÄrÅI¹µÄµÜ¤B
ÁÉALÌURLª·ï¿½ï¿½êà é¾ë¤©çAÎôÉÍ¿åÁÆHvªKv¾ (bit.ly ÈÇÌ URL ZkT[rXðg¤ÈÇ)B
»ê©çAÇÌLð Twitter Éã��½©ÇµÄ��È��ÌÅAÉÔª©©ÁĵܤB
(d¡µ½LÍe³ê¸ATwitter ¤ÅÌÄÄêé椾)
d¡eðð¯éÉÍAÇÌLðeµ½©f[^x[XÅÇ·éÈÇA½ç©ÌdgݪKv¾B