NeverBlog::Likk::Unexistable;

見なかったことにして下さい

mixi@寄せ辺β 仮復帰

コア部分は、ほぼMSNと同じロジック。

例によって、コア部分以外のソース一部さらし。

#!/usr/local/bin/perl
package main;
use strict;
use warnings;
use lib qw('ユーザLib領域');
use WWW::Mixi;
use Data::Dumper;
use Date::Parse;
use Encode qw/encode decode/;
use Encode::EUCJPMS;
use JN;

local $| =1;
local $\ ="\n";
my $my_name = "よせなべりん";
Encode::from_to($my_name, "utf8", "eucJP-ms");

#ミクシィにログイン
my $mixi = WWW::Mixi->new('ログインID', 'パスワード');
	$mixi->login();

#========================================
#マイミク最新日記にコメントする

#マイミク最新日記一覧の取得
my @c = $mixi->get_new_friend_diary();
for my $line (@c){
	my $diary_ad = $line->{link};
	my $reg_date = $line->{time};
	$reg_date =~ s{/}{-}g;
	my $epoctime = str2time($reg_date);
	my $time_diff = time - $epoctime;
	#一週間以上前の日記は、コメントされても今更感が漂うので、無視。
	next if $time_diff > 3600 * 24 * 7;
		#各日記の詳細ページに飛ぶ
		friend_diary_args($diary_ad)
}
#========================================

exit(0);

#マイミク最新日記取得
sub friend_diary_args{
	my $response = shift;
	my $res = $mixi->get($response => 'refresh');
	
	#マイミク最新日記の詳細を取得
	my @diarys = $mixi->parse_view_diary($res);
	for my $diary_ref (@diarys){
		my $comented = 0;
		my @comments = $diary_ref->{'comments'};

		#既に自分のコメントがある場合はコメントしない
		for my $comment(@comments){
			for my $hash (@$comment){
				$comented = 1 if $hash->{'name'} eq $my_name;
			}
		}
		next if $comented ==1;
		
		#日記タイトルと、本文くっ付ける。余分なスペースや改行は削除
		$diary_ref->{'description'} =~ s{\n+}{\n}g;
		my $diary = $diary_ref->{'subject'}."\n".$diary_ref->{'description'};
		
		#日記のURLデータの取得
		my @url_data = split/\?/,$response;
		my @param = split/&/,$url_data[1];
		my (undef,$diary_id) = split /=/,$param[0];
		my (undef,$owner_id) = split /=/,$param[1];

		#日記データで必要なものだけメインに渡す
		my $word = main_args($diary,$diary_id,$owner_id);
	}
}

#日記のデータに対して、人工無能っぽいことをさせる
sub main_args{
	my $message = shift;
	my $diary_id = shift;
	my $owner_id = shift;
	
	#寄せ辺設定取得
	my $jn_obj = JN->new();

	##DB設定
	$jn_obj->set_MyDB();	
	$jn_obj->DB_connect();
	
	$message =~ s/^\s*//;
	$message =~ s/\s*$//;
	my $responce ="none";
	$responce = $JNM_obj->do_action($message);#コア部、ユーザの発言をごにょごにょ人工無能っぽいことして、発言内容を決める(メソッド名は適当です)

	#DB切断	
	$jn_obj->DB_disconnect();


	if($responce ne 'none'){	
		#上手く、返答を作成できたら、日記に対して投稿する
		#投稿画面
		my $target = qq|diary_id=$diary_id&owner_id=$owner_id|;
		my $post_usl = qq|add_comment.pl?$target&comment_body=$responce|;
		#確認画面
		my $post_data = Dumper $mixi->post($post_usl);
		$post_data =~ m{<input type="hidden" name="post_key"(\s+)value="([a-z0-9]+)"};
		my $post_key = $2;
		#コメントの投稿確定
		my $post_commit = qq|add_comment.pl?$target&submit=confirm&post_key=$post_key&comment_body=$responce|;
		$mixi->post($post_commit);
	}
	return $responce;
}