[Affelio-cvs 821] CVS update: affelio/lib/Affelio/Managing

Back to archive index

Tadashi Okoshi slash****@users*****
2005年 12月 10日 (土) 08:07:38 JST


Index: affelio/lib/Affelio/Managing/NewsAggregator.pm
diff -u affelio/lib/Affelio/Managing/NewsAggregator.pm:1.2 affelio/lib/Affelio/Managing/NewsAggregator.pm:1.3
--- affelio/lib/Affelio/Managing/NewsAggregator.pm:1.2	Sat Dec 10 07:18:29 2005
+++ affelio/lib/Affelio/Managing/NewsAggregator.pm	Sat Dec 10 08:07:38 2005
@@ -14,12 +14,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
-# $Id: NewsAggregator.pm,v 1.2 2005/12/09 22:18:29 slash5234 Exp $
+# $Id: NewsAggregator.pm,v 1.3 2005/12/09 23:07:38 slash5234 Exp $
 
 package Affelio::Managing::NewsAggregator;
 {
     use strict;
     use lib("../../../extlib");    
+    use Error qw(:try);
     use DBI;
     use Jcode;
     use lib("../../");
@@ -29,6 +30,7 @@
     use Affelio::misc::Debug qw(debug_print);
     use Affelio::misc::WSSE;
     use Affelio::SNS::Handshaker_c;
+    use Affelio::exception::NetworkException;
     use Affelio::exception::CommunicationException;
 
     #######################################################################
@@ -50,6 +52,51 @@
     }
 
     #######################################################################
+    #post_news
+    #######################################################################
+    sub post_news{
+	my $self = shift;
+	my $af = $self->{af}; 
+
+	my %arg = @_;
+
+	##############################
+	#Insert a new record
+	my $sth = "insert into AFuser_CORE_nghr_news(datetime, af_id, nickname, app_install_name, title, description, creator, URL) values ('$arg{datetime}', '$arg{af_id}', '$arg{nickname}', '$arg{app_install_name}', '$arg{title}', '$arg{description}', '$arg{creator}', '$arg{URL}')";
+	eval{
+	    $sth = $af->getDB->prepare($sth);
+	    $sth->execute;
+	};
+	if($@){
+	    throw Affelio::exception::DBException($af->getDB->errstr);
+	}
+	undef($sth);
+
+
+
+
+#	    this->post_news(datetime => $datetime,
+#			    af_id => $af_id,
+#			    nickname => $nickname,
+#			    app => $app_install_name,
+#			    title => $title,
+#			    desc => $desc,
+#			    creator => $creator,
+#			    URL => $URL);
+
+#	CREATE TABLE AFuser_CORE_nghr_news(nid INTEGER PRIMARY KEY AUTOINCREMENT, 
+#				   datetime INTEGER,
+#				   af_id TEXT,
+	#			   nickname TEXT,
+#				   app_install_name TEXT,
+#				   title TEXT,
+#				   description TEXT,
+#				   creator TEXT,
+#					   URL TEXT);
+    }
+
+
+    #######################################################################
     #get_one
     #######################################################################
     sub get_one{
@@ -60,13 +107,17 @@
 
 	#########################################################
 	#Get a friend whose last_news_in is smallet (oldest).
-	my $result = $af->getFM->get_all_friend_list(sort => "last_news_in",
+	my $threshold = Affelio::misc::Time::get_timestamp();# - 1000; #-10m
+	my $result = $af->getFM->get_all_friend_list(where => "last_news_in  < $threshold",  
+						     sort => "last_news_in",
 						     order => "desc");
-
 	my @row = $result->fetchrow_array;
-	#uid, af_id, nickname, timestamp, password, intro, option_pid, lastupdated, f2list, last_news_in, last_news_out
+	if(!@row){ return; }
 
+	#uid, af_id, nickname, timestamp, password, intro, option_pid, lastupdated, f2list, last_news_in, last_news_out
+	my $uid = $row[0];
 	my $af_id = $row[1];
+	my $nickname = $row[2];
 	my $password = $row[4];
 
 	#########################################################
@@ -82,17 +133,54 @@
 			    xwsse_mesg => $xwsse_mesg);
 
 	}catch Affelio::exception::NetworkException with{
-	    my $E = shift;
-	    throw Affelio::exception::CommunicationException($E);
-	}catch Error with{
-	    my $E = shift;
-	    throw Affelio::exception::Exception($E);
+	    my $e = shift;
+	    throw Affelio::exception::CommunicationException($e);
 	};
 
 	#########################################################
 	#Analyze returned value
 	debug_print("NewsAggregator::get_one: ret=[$ret]");
 
+	#########################################################
+	#Post data into NeighborNews table
+	my @elements = split('\n', $ret->{message});
+	my $size = @elements;
+	my $index=0;
+	while($index < $size){
+	    my $datetime = $elements[$index++];
+	    my $app_install_name = $elements[$index++];
+	    my $title = $elements[$index++];
+	    my $desc = $elements[$index++];
+	    my $creator = $elements[$index++];
+	    my $URL = $elements[$index++];
+
+	    debug_print("NewsAggregator::get_one: date = $datetime");
+	    debug_print("NewsAggregator::get_one: afid = $af_id");
+	    debug_print("NewsAggregator::get_one: app = $app_install_name");
+	    debug_print("NewsAggregator::get_one: title= $title");
+	    debug_print("NewsAggregator::get_one: desc= $desc");
+	    debug_print("NewsAggregator::get_one: creator= $creator");
+	    debug_print("NewsAggregator::get_one: URL = $URL");
+
+
+	    post_news($self,
+		      datetime => $datetime,
+		      af_id => $af_id,
+		      nickname => $nickname,
+		      app => $app_install_name,
+		      title => $title,
+		      desc => $desc,
+		      creator => $creator,
+		      URL => $URL);
+	}
+
+
+	#########################################################
+	#update AFuser_CORE_friends
+	my $curtime = Affelio::misc::Time::get_timestamp();
+	my $result = $af->getFM->set_attribute_by_id($uid,
+						     "last_news_in",
+						     $curtime);
     }
 
 


Affelio-cvs メーリングリストの案内
Back to archive index