From ab265403df6d57311a7a5839e0f664ecd97bf8a7 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sat, 23 Oct 2010 13:47:35 +0200 Subject: [PATCH] move save_marc to Scraper --- Aleph.pm | 14 ++------------ Scraper.pm | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Aleph.pm b/Aleph.pm index 4e25c57..4c27f5a 100644 --- 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; diff --git a/Scraper.pm b/Scraper.pm index e1b13f4..8920978 100644 --- a/Scraper.pm +++ b/Scraper.pm @@ -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; -- 2.20.1