#!/usr/local/bin/perl #ex) # # use IO::Socket; require './jcode.pl'; my $id = 'kuwa'; my $num = 40; #表示数 my $encode = 'euc'; #'euc' or 'jis' or 'sjis' my $sep = ' | '; ###################設定ここまで############## my $http_version = '1.1'; my $timeout = 10; #print qq|Content-type: text/html\n\n|; print qq|Content-Type: application/x-javascript\n\n|; &getNews('a.hatena.ne.jp',"/$id/source?mode=lirs",80,$num,$encode); exit; sub getNews{ my ($host,$uri,$port,$max,$code)=@_; $port or ($port=80); $datb or ($datb='>'); $date or ($date='<'); my $f=0; my $news; my $i=1; ($max==0) && ($max=10); my $list; my $i=1; foreach( &get_content( $host, $uri, $port ) ){ next if($_!~/^LIRS/); jcode::convert(\$_, 'sjis',$code); s/\x0d?\x0a?$//; my @LINE = split(/,/,$_); my $title = &get_time($LINE[1]); #URLをはてな互換に my $time = &get_time($LINE[1],1); # $LINE[5] =~ s/http/http:\/\/a.hatena.ne.jp\/go?http/; $LINE[5] = "http://a.hatena.ne.jp/go?$LINE[5]$time"; my $line .= qq|$LINE[6]|; $list .= qq|document.write('|; $list .= $line; $list .= $sep; $list .= qq|')\n|; last if($i>=$max); $i++; } close(S); print $list; } ############################## sub get_content{ my ($host,$uri,$port) = @_; $port or ($port = 80); socket(S, PF_INET, SOCK_STREAM, getprotobyname('tcp')); my $sin = pack("S n a4 x8", 2, $port, (gethostbyname($host))[4]); if (connect(S, $sin)){ select(S); $| = 1; select(STDOUT); print S <<"_EOM_"; GET $uri HTTP/1.0 Host: $host User-Agent: get_antena/1.0 ( http://cgi.au-lait.net/\; $ENV{OSTYPE}\; $ENV{HOSTTYPE}) _EOM_ return ; } return; } sub get_time{ my $times = shift; my $mode = shift; my(@ts) = gmtime($times); $ts[4]++; $ts[5] += 1900; if($mode){ return sprintf("%04d%02d%02d%02d%02d%02d",$ts[5],$ts[4],$ts[3],$ts[2],$ts[1],$ts[0]); } else { return sprintf("更新 %04d/%02d/%02d %02d:%02d:%02d",$ts[5],$ts[4],$ts[3],$ts[2],$ts[1],$ts[0]); } } ##############################