import cover images from filesystem and create biblio and items
authorDobrica Pavlinusic <dpavlin@rot13.org>
Mon, 16 Apr 2012 23:18:13 +0000 (01:18 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Wed, 25 Apr 2012 22:01:25 +0000 (00:01 +0200)
misc/gimpoz/import-images.pl [new file with mode: 0755]

diff --git a/misc/gimpoz/import-images.pl b/misc/gimpoz/import-images.pl
new file mode 100755 (executable)
index 0000000..2c72569
--- /dev/null
@@ -0,0 +1,68 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use autodie;
+use Data::Dump qw(dump);
+
+use MARC::Record;
+
+$|=1;
+use lib '/srv/koha_gimpoz/';
+
+BEGIN {
+       $ENV{KOHA_CONF} = '/etc/koha/sites/gimpoz/koha-conf.xml';
+}
+use C4::Images;
+use C4::Biblio;
+use C4::Items;
+
+my $source_dir = '/data/gimpoz/dvd1';
+my $replace = 1;
+my $frameworkcode = '';
+
+sub marc {
+       my $marc = {@_};
+       print "MARC ",dump($marc),$/;
+}
+
+my $biblionumber;
+
+open(my $find, '-|', qq{find $source_dir -iname "*.jpg" | sort});
+while(<$find>) {
+       chomp;
+       my $path = $_;
+       warn "# path $path\n";
+       s{^\Q$source_dir\E/*}{};
+       my $student = $1 if s{^(.+?)/}{};
+       $student =~ s/^(\d+).*/$1/;
+       my $lokacija = $1 if s{^(.+?)/}{};
+
+       my $inventarni_broj = $_;
+       $inventarni_broj =~ s/\.jpg$//i;
+
+       if ( $inventarni_broj =~ m/\s*-\s*([a-k])\s*$/i ) {
+               warn "# $biblionumber dio $1\n";
+       } else {
+               my $record = MARC::Record->new;
+               $record->add_fields(
+                       [ 245, " ", " ", a => $inventarni_broj ],
+                       [ 952, " ", " ", t => $inventarni_broj ],
+               );
+
+               my $biblioitemnumber;
+               ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode);
+               warn "# AddBiblio $biblionumber $biblioitemnumber [$inventarni_broj]\n";
+
+               my ($biblionumber, $biblioitemnumber, $itemnumber)
+                       = AddItemFromMarc($record, $biblionumber);
+
+               warn "# AddItemFromMarc $biblionumber $biblioitemnumber $itemnumber\n";
+
+       }
+
+       my $image = GD::Image->new($path);
+       PutImage($biblionumber, $image, $replace);
+
+       print dump( $biblionumber, $student, $lokacija, $inventarni_broj ),$/;
+}
+