root/lang/perl/WWW-Mixi-Scraper/trunk/get_sources.pl @ 17200

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 
1use strict;
2use warnings;
3use lib 'lib';
4use YAML;
5use Encode;
6use HTTP::Cookies;
7use WWW::Mixi::Scraper;
8use Getopt::Long;
9use File::Path;
10
11GetOptions(\my %options => qw( force|f ));
12
13mkpath 't_live/cookies' unless -d 't_live/cookies';
14
15my $conf = YAML::LoadFile('live_test.yml');
16my $cookie_jar = HTTP::Cookies->new(
17  file     => 't_live/cookies/mixi.dat',
18  autosave => 1,
19);
20my $mixi = WWW::Mixi::Scraper->new(
21  email      => $conf->{global}->{email},
22  password   => $conf->{global}->{password},
23  cookie_jar => $cookie_jar,
24);
25
26if ( $conf->{global}->{test_html_dir}
27     && !-d $conf->{global}->{test_html_dir}
28) {
29  mkpath( $conf->{global}->{test_html_dir} );
30}
31
32foreach 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}
Note: See TracBrowser for help on using the browser.