#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use GD;
use Config::Pit;
use Encode;
use URI::Fetch;
use XML::Feed;
use WWW::Mechanize;
# JAGAT SNSの自分のアカウント情報はConfig::Pitで
# あらかじめセットしておこう。コマンドラインからは
# $ perl -MConfig::Pit -e'Config::Pit::set("www.jagat.jp", data=>{ username => "ABC12345", password => "password" })'
my $config = pit_get("www.jagat.jp");
die "not preset account data in Pit." if !%$config;
my $username = $config->{username} or die 'username not found.';
my $password = $config->{password} or die 'password not found.';
# ダミー画像(1x1pxの白のgif画像)のファイル名。無ければ作る。
my $dummy_image = 'dummy.gif';
# Mechanize 初期化
my $mech = WWW::Mechanize->new();
$mech->agent_alias( 'Windows Mozilla' );
# Main
set_dummy();
write_sns();
exit;
sub set_dummy {
return if -e $dummy_image;
my $im = new GD::Image(1,1);
$im->fill(0,0, $im->colorAllocate(255,255,255) );
open my $fh, '>', $dummy_image or die $!;
print $fh $im->gif;
close $fh;
return;
}
sub write_sns {
# JAGAT SNSログイン
login( $username, $password );
# 日記書き込み
post( "タイトル", "本文" ); # JAGAT SNSへ投稿
return;
}
sub login { # JAGAT SNSへログイン
my $username = shift;
my $password = shift;
my $res = $mech->get('http://www.jagat.jp/mypage/login.php');
$mech->form_number(2);
$mech->set_visible( $username, $password );
$mech->submit();
die 'Login Failed.' if ($mech->uri() =~m|https://www.jagat.jp/index.php?option=login|);
return;
}
sub post { # JAGAT SNS Todoへ投稿
my $subject = shift;
my $body = shift;
my $res = $mech->get('http://www.jagat.jp/igns/?m=pc&a=page_h_diary_add');
$mech->form_number(1); # HTML内の1番目のフォーム
$mech->set_fields(
subject => $subject,
body => $body,
public_flag => 'private',
upfile_1 => $dummy_image,
upfile_2 => $dummy_image,
upfile_3 => $dummy_image,
);
$mech->submit(); # 送信
sleep 3;
$mech->form_number(1); # HTML内の1番目のフォーム
$mech->submit(); # 送信
return;
}
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mixi::Scraper;
use XML::Feed;
use DateTime::Format::HTTP;
use Config::Pit;
my $config = pit_get( 'mixi.jp' );
die "not preset account data in Pit." if !%$config;
my $email = $config->{email} or die 'email not found.';
my $password = $config->{password} or die 'password not found.';
my $mixi = WWW::Mixi::Scraper->new(
email => $email,
password => $password,
);
my @list = $mixi->parse( 'http://mixi.jp/list_diary.pl' );
my $rss = XML::Feed->new( 'RSS',
version => '1.0', encode_output => 0 );
$rss->title( 'mixi My Diary RSS' );
foreach my $item ( @list ) {
my $entry = XML::Feed::Entry->new( 'RSS' );
$entry->title ( $item->{subject} );
$entry->link ( $item->{link } );
$entry->content( $item->{description } );
my $dt = DateTime::Format::HTTP
->parse_datetime( $item->{time} )
->set_time_zone( 'Asia/Tokyo' );
$entry->issued ( $dt );
$rss->add_entry( $entry );
}
print "Content-Type: text/xml; charset=UTF-8;\n\n";
print $rss->as_xml,"\n";
exit;
__END__