|
Revision 17200, 1.2 kB
(checked in by charsbar, 5 years ago)
|
|
WWW-Mixi-Scraper: added get_sources.pl to make live tests easier; this is just for repository users and shouldn't go into the distribution.
|
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | use strict; |
|---|
| 2 | use warnings; |
|---|
| 3 | use lib 'lib'; |
|---|
| 4 | use YAML; |
|---|
| 5 | use Encode; |
|---|
| 6 | use HTTP::Cookies; |
|---|
| 7 | use WWW::Mixi::Scraper; |
|---|
| 8 | use Getopt::Long; |
|---|
| 9 | use File::Path; |
|---|
| 10 | |
|---|
| 11 | GetOptions(\my %options => qw( force|f )); |
|---|
| 12 | |
|---|
| 13 | mkpath 't_live/cookies' unless -d 't_live/cookies'; |
|---|
| 14 | |
|---|
| 15 | my $conf = YAML::LoadFile('live_test.yml'); |
|---|
| 16 | my $cookie_jar = HTTP::Cookies->new( |
|---|
| 17 | file => 't_live/cookies/mixi.dat', |
|---|
| 18 | autosave => 1, |
|---|
| 19 | ); |
|---|
| 20 | my $mixi = WWW::Mixi::Scraper->new( |
|---|
| 21 | email => $conf->{global}->{email}, |
|---|
| 22 | password => $conf->{global}->{password}, |
|---|
| 23 | cookie_jar => $cookie_jar, |
|---|
| 24 | ); |
|---|
| 25 | |
|---|
| 26 | if ( $conf->{global}->{test_html_dir} |
|---|
| 27 | && !-d $conf->{global}->{test_html_dir} |
|---|
| 28 | ) { |
|---|
| 29 | mkpath( $conf->{global}->{test_html_dir} ); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | foreach my $plugin ( keys %{ $conf->{tests} } ) { |
|---|
| 33 | my $ct = ''; |
|---|
| 34 | foreach my $item ( @{ $conf->{tests}->{$plugin} || [] } ) { |
|---|
| 35 | my $options = $item->{remote} || $item->{source} || next; |
|---|
| 36 | $options = {} if $options eq '-'; |
|---|
| 37 | |
|---|
| 38 | my $file = "t_live/html/$plugin$ct.html"; |
|---|
| 39 | $ct ||= 1; $ct++; |
|---|
| 40 | next if -f $file and !$options{force}; |
|---|
| 41 | print $file,"\n"; |
|---|
| 42 | |
|---|
| 43 | my $content = $mixi->$plugin->get_content(%{ $options }); |
|---|
| 44 | open my $fh, '>', $file; |
|---|
| 45 | print $fh encode( 'euc-jp' => $content ); |
|---|
| 46 | close $fh; |
|---|
| 47 | } |
|---|
| 48 | } |
|---|