Skip to content

Instantly share code, notes, and snippets.

@makotoworld
Created March 12, 2010 06:54
Show Gist options
  • Save makotoworld/330097 to your computer and use it in GitHub Desktop.
Save makotoworld/330097 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# deaf_blog_yahoo_api.pl
use strict;
use warnings;
use WebService::Simple;
use WebService::Simple::Parser::JSON;
use Perl6::Say;
use Data::Dumper;
use Encode;
my @query = qw/聴覚障害 手話 聴覚障がい 聴力障害 ろうあ者/;
my $start = 0;
sub yahoo_blog{
my ($query) = @_;
my $parser = WebService::Simple::Parser::JSON->new;
$parser->{json}->utf8(1);
my $yahoo = WebService::Simple->new(
base_url => "http://search.yahooapis.jp/BlogSearchService/V1/blogSearch",
response_parser => $parser,
params => { appid => "xxx", type => "article", results => "50", term => "month", output => "json" }
);
my $response = $yahoo->get( { query => $query, start => $start } );
my $max_count = 0;
if($response->parse_response->{"\@attributes"}->{totalResultsAvailable} < 1000){
$max_count = $response->parse_response->{"\@attributes"}->{totalResultsAvailable};
}else{
$max_count = 1000;
}
say $query;
say $response->parse_response->{"\@attributes"}->{totalResultsAvailable},"件";
while($start < $max_count){
$response = $yahoo->get( { query => $query, start => $start } );
# say Dumper($response->parse_response);
foreach my $item (@{$response->parse_response->{Result}}){
say $item->{DateTime};
say $item->{Id};
if(ref($item->{mobileLink}) ne "HASH"){
say $item->{mobileLink};
}
if(ref($item->{Creator}) ne "HASH"){
say $item->{Creator};
}
say $item->{Title};
say $item->{RssUrl};
say $item->{Site}->{Url};
say $item->{Site}->{Title};
say $item->{Url};
say $item->{Descaption};
}
$start = $start + 50;
}
}
#yahoo_blog("iphone");
foreach(@query){
utf8::decode($_);
yahoo_blog($_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment