use also MKP homebranch
[koha-eprints] / mkp-marc.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use autodie;
7 use DBI;
8 use Data::Dump qw/dump/;
9
10 my $limit = $ENV{LIMIT} || 10;
11
12 my $dsn = 'DBI:mysql:dbname=koha_ffzg';
13 my $sql = qq{
14 select
15         biblionumber,title,
16         marc
17 from items
18         join biblioitems using (biblionumber)
19         join biblio using (biblionumber)
20 where location = 'MKP'
21         or homebranch = 'MKP'
22 limit $limit
23 };
24
25 my $path = "/dev/shm/$1" if $dsn =~ m/=(.+)/;
26
27 open(my $marc_fh, '>', "$path.marc");
28 open(my $tsv_fh,  '>', "$path.tsv");
29
30 warn "# dsn = $dsn";
31 my $dbh = DBI->connect( $dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;
32 #$dbh->do( qq{ set client_encoding='utf-8' } );
33
34 warn "# sql $sql";
35 my $sth = $dbh->prepare( $sql );
36 $sth->execute();
37
38 warn "# ", $sth->rows,"\n";
39
40 my $i = 1;
41
42 while ( my $row = $sth->fetchrow_hashref ) {
43
44 #       warn "# row = ",dump( $row );
45
46         my $rec = tell $marc_fh;
47         foreach ( keys %$row ) {
48                 my $d = $row->{$_};
49
50                 if ( m/marc/ ) {
51                         print $marc_fh $row->{marc};
52                         next;
53                 }
54
55                 next unless defined $d;
56
57 #               $d =~ s{</?\w+>}{ }gs;
58 #               $d =~ s/\s+/ /gs;
59
60                 $rec .= "\t$d";
61
62         }
63
64         print $tsv_fh "$rec\n";
65 }
66
67 system "ls -al $path*";
68 system "rsync -v $path* 10.60.0.82:/tmp/";