move save_marc to Scraper
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 23 Oct 2010 11:47:35 +0000 (13:47 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 23 Oct 2010 11:47:35 +0000 (13:47 +0200)
Aleph.pm
Scraper.pm

index 4e25c57..4c27f5a 100644 (file)
--- a/Aleph.pm
+++ b/Aleph.pm
@@ -9,7 +9,7 @@ use Data::Dump qw/dump/;
 use base 'Scraper';
 
 sub diag {
-       print "# ", @_, $/;
+       warn "# ", @_, $/;
 }
 
 # Koha Z39.50 query:
@@ -147,20 +147,10 @@ diag "sf = ", dump(@sf);
 
                my $id = $hash->{SYS} || die "no SYS";
 
-               my $path = "marc/$id.$format";
-
-               open(my $out, '>:utf8', $path) || die "$path: $!";
-               print $out $marc->as_usmarc;
-               close($out);
-
-               diag "created $path ", -s $path, " bytes";
-
-#              diag $marc->as_formatted;
+               $self->save_marc( $id, $marc->as_usmarc );
 
                $nr++;
 
-               die if $nr == 3; # FIXME
-
                $mech->follow_link( url_regex => qr/set_entry=0*$nr/ );
 
                return $marc->as_usmarc;
index e1b13f4..8920978 100644 (file)
@@ -5,8 +5,6 @@ use strict;
 
 use WWW::Mechanize;
 
-binmode STDOUT, ':utf8';
-
 sub new {
     my ( $class ) = @_;
     my $self = {
@@ -16,3 +14,21 @@ sub new {
     return $self;
 }
 
+sub save_marc {
+       my ( $self, $id, $marc ) = @_;
+
+       my $database = ref $self;
+       mkdir 'marc' unless -e 'marc';
+       mkdir "marc/$database" unless -e "marc/$database";
+
+       my $path = "marc/$database/$id";
+
+       open(my $out, '>:utf8', $path) || die "$path: $!";
+       print $out $marc;
+       close($out);
+
+       warn "# created $path ", -s $path, " bytes";
+
+}
+
+1;