Created
June 3, 2009 17:19
-
-
Save kyanny/123105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use XML::Simple; | |
use URI; | |
use Perl6::Say; | |
use Data::Dumper; | |
use YAML; | |
my $url = 'http://twitter.com/statuses/user_timeline/10557722.rss'; | |
my $api = 'http://jlp.yahooapis.jp/KeyphraseService/V1/extract'; | |
my $appid = 'appid'; | |
my @keyphrase; | |
my $ua = LWP::UserAgent->new; | |
my $res = $ua->get($url); | |
if ($res->is_success) { | |
my $ref = XMLin($res->content); | |
for my $item (@{ $ref->{channel}->{item} }) { | |
my $sentence = $item->{title}; | |
$sentence =~ s/^\w+:\s//g; | |
my %sentence; | |
$sentence{$sentence} = []; | |
my $uri = URI->new($api); | |
$uri->query_form( | |
appid => $appid, | |
sentence => $sentence, | |
); | |
my $res = $ua->get($uri); | |
if ($res->is_success) { | |
my $ref = XMLin($res->content); | |
for my $result (@{ $ref->{Result} }) { | |
my $keyphrase = $result->{Keyphrase}; | |
push @{$sentence{$sentence}}, $keyphrase; | |
} | |
} | |
push @keyphrase, \%sentence; | |
} | |
} | |
print YAML::Dump(\@keyphrase); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment