zhangbo-NLP-plugin_eng/lib/zhangbo/NLP/uniq.pl
#!/usr/bin/perl
#use JSON::XS;
use MongoDB;
use Smart::Comments;
use lib "/home/wyb/shell/";
use Conn_mongo_jc;
use Data::Dumper;
use IO::File;
#use Add_info;
# http://poe.perl.org/?POE_Cookbook/TCP_Servers
# Include POE and POE::Component::Server::TCP.
$hash=();
use POE qw(Component::Server::TCP);
my $col = Conn_mongo_jc->new("xs_data", "filter_data");
my $news=$col->find();
while(my $one =$news->next)
{
$id=$one->{'id'};
$hash->{$id}=1;
}
# Start a TCP server. Client input will be logged to the console and
# echoed back to the client, one line at a time.
#use lib "/var/www";
print "$id";
print "start server ok\n";
open(FD,">/tmp/uniq.log");
my $n=0;
POE::Component::Server::TCP->new(
Alias => "echo_server",
Port => 11211,
ClientInput => sub {
my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
# print "Session ", $session->ID(), " got input: ".$input."\n";
#print "Session ", $session->ID(), " got input: ".length($input)."\n";
# $heap->{client}->put($input);
chomp($input);
$input=~/(.*?)\#\#\#(.*?)\#\#\#(.*)/g;
$mid=$1;
$channel=$2;
$time=$3;
#print "mid =$mid\n";
if(exists($hash->{$mid}))
{
$heap->{client}->put("1\n");
print FD "old $input\n";
# $heap->{client}->stop();
# $session->stop();
}
else
{
$heap->{client}->put("0\n");
$col->insert({'id'=>"$mid","channel"=>"$channel","time"=>$time});
$hash->{$mid}=1;
print FD "new $input\n";
# $heap->{client}->stop();
# $session->stop();
}
}
);
# Start the server.
$poe_kernel->run();
sub ndate
{
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time());
$year=~s/1(.*)/20$1/;
$mon+=1;
if($mon=~/^\d$/)
{
$mon="0"."$mon";
}
if($mday=~/^\d$/)
{
$mday="0"."$mday";
}
if($hour=~/^\d$/)
{
$hour="0"."$hour";
}
if($min=~/^\d$/)
{
$min="0"."$min";
}
if($sec=~/^\d$/)
{
$sec="0"."$sec";
}
my $res=$year."-".$mon."-".$mday." ".$hour.":"."$min".":"."$sec";
#print $res,"\n";
$res;
}