| 1 | #!/usr/bin/env perl | ||
| 2 | # | ||
| 3 | # Scrape an existing Yahoo 360 blog by supplying | ||
| 4 | # the username and password. | ||
| 5 | # | ||
| 6 | # $Id$ | ||
| 7 | |||
| 8 | BEGIN { $| = 1 } | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | use Getopt::Long; | ||
| 14 | use JSON::XS; | ||
| 15 | use WWW::Scraper::Yahoo360; | ||
| 16 | |||
| 17 | our $verbose; | ||
| 18 | our $debug; | ||
| 19 | |||
| 20 | sub debug { | ||
| 21 | if ($verbose) { | ||
| 22 | print STDERR @_, "\n"; | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | GetOptions( | ||
| 27 | 'username:s' => \my $username, | ||
| 28 | 'password:s' => \my $password, | ||
| 29 | 'verbose' => \$verbose, | ||
| 30 | 'debug' => \$debug, | ||
| 31 | ); | ||
| 32 | |||
| 33 | if (! $username || ! $password) { | ||
| 34 | die "$0 --username=<yahoo_id> --password=<yahoo_password> [--verbose] [--debug]\n"; | ||
| 35 | } | ||
| 36 | |||
| 37 | # Global debug flag | ||
| 38 | $WWW::Scraper::Yahoo360::DEBUG = $debug ? 1 : 0; | ||
| 39 | |||
| 40 | my $y360 = WWW::Scraper::Yahoo360->new({ | ||
| 41 | username => $username, | ||
| 42 | password => $password, | ||
| 43 | }); | ||
| 44 | |||
| 45 | debug("Yahoo scraper initialized. Trying to login as '$username'."); | ||
| 46 | |||
| 47 | $y360->login() or die "Can't login to Yahoo!"; | ||
| 48 | |||
| 49 | debug("Logged in successfully. Getting blog information."); | ||
| 50 | |||
| 51 | my $blog_info = $y360->blog_info(); | ||
| 52 | |||
| 53 | debug("Got blog information. Reading blog posts..."); | ||
| 54 | |||
| 55 | my $posts = $y360->get_blog_posts(); | ||
| 56 | $blog_info->{items} = $posts; | ||
| 57 | |||
| 58 | debug("Reading all blog comments..."); | ||
| 59 | |||
| 60 | my $comments = $y360->get_blog_comments($posts); | ||
| 61 | $blog_info->{comments} = $comments; | ||
| 62 | |||
| 63 | my $json = JSON::XS->new()->pretty; | ||
| 64 | print $json->encode($blog_info); | ||
| 65 |