move save_marc to Scraper
[Biblio-Z3950.git] / Scraper.pm
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;