Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created June 3, 2009 17:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kyanny/123105 to your computer and use it in GitHub Desktop.
Save kyanny/123105 to your computer and use it in GitHub Desktop.
#!/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