▼ [WWW] ニコニコ動画の更新情報をTwitterに流す
2007/11/09 0:49
ニコニコ動画の更新情報をTwitterに流す実験:
updatetwitter.pl:
#! /usr/bin/perl
use strict;
use warnings;
use open OUT => ":encoding(euc-jp)";
use YAML qw[LoadFile];
use Data::Dumper;
use DB_File;
use Fcntl;
use Digest::MD5 qw[md5_hex];
use XML::RSS::Parser;
use Net::Twitter;
MAIN: {
my $conf = LoadFile("etc/twitter.yml") || die $!;
tie(my %db, DB_File => $conf->{read_db}, O_RDWR|O_CREAT, 0644) or die $!;
foreach my $e (@{$conf->{targets}}) {
my $twit = Net::Twitter->new(username=> $e->{username},
password=> $e->{password}) || die $!;
foreach my $t (@{$e->{tags}}) {
my $rssfile = sprintf $conf->{rss_path}, "tag", md5_hex($t);
open my $fh, "<", $rssfile or die $!;
my $feed = XML::RSS::Parser->new->parse_file($fh);
my $count = 0;
foreach my $i ($feed->query("//item")) {
my $title = $i->query("title")->text_content;
my $link = $i->query("link")->text_content;
utf8::encode($title);
my $key = "$e->{username};$link";
if(not exists $db{$key}) {
$twit->update("$link $title");
$db{$key} = time;
sleep 3;
last if(3 <= ++$count);
}
}
}
}
}
etc/config.yml (utf-8):
rss_path: rss/%s/%s.rss
read_db: var/rss_read.db
targets:
- username: vocaloid
password: ########
tags:
- 初音ミク
- 鏡音リン
- username: idolmaster
password: ########
tags:
- アイドルマスター
- アイマス
▼ コメント(0件)
- TB-URL(確認後に公開) http://diary.asuka.net/036/tb/
