move save_marc to Scraper
[Biblio-Z3950.git] / Scraper.pm
1 package Scraper;
2
3 use warnings;
4 use strict;
5
6 use WWW::Mechanize;
7
8 sub new {
9     my ( $class ) = @_;
10     my $self = {
11                 mech => WWW::Mechanize->new(),
12         };
13     bless $self, $class;
14     return $self;
15 }
16
17 sub save_marc {
18         my ( $self, $id, $marc ) = @_;
19
20         my $database = ref $self;
21         mkdir 'marc' unless -e 'marc';
22         mkdir "marc/$database" unless -e "marc/$database";
23
24         my $path = "marc/$database/$id";
25
26         open(my $out, '>:utf8', $path) || die "$path: $!";
27         print $out $marc;
28         close($out);
29
30         warn "# created $path ", -s $path, " bytes";
31
32 }
33
34 1;