added simple import script
[eprints3-migration.git] / tsv2xp-xml.pl
index 2991632..6799778 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
-# sudo -u eprints /usr/share/eprints3/bin/import --verbose --migration ffzg eprint XML dipl.xml
+# ./tsv2xp-xml.pl 2>/dev/null > ep-diplomski.xml
+# sudo -u eprints /usr/share/eprints3/bin/import --verbose --migration ffzg eprint XML ep-diplomski.xml
 
 use warnings;
 use strict;
@@ -8,9 +9,7 @@ use strict;
 use File::Slurp;
 use Data::Dump qw(dump);
 
-my $tsv_file = 'items.mentor_ime.mentor_perzime.IME_FILE_a.PREZIME.IME.NAZIV_RADA.MENTOR.GOD_OBR63a8814e199c9b969dbe8251fdef0fa2';
-
-our $eprintsid = 700;
+my $tsv_file = ( glob 'items.*' )[0];
 
 my $xml = read_file 'ep-xml.xml';
 my @files = read_file "files.txt";
@@ -65,12 +64,24 @@ while(<$tsv>) {
        if ( my $full = $file2path->{ lc $file } ) {
                $full_path = $full;
                warn "# file $file -> $full_path\n";
+               $file .= $1 if $full_path =~ m/(\.\w+)$/;
+       }
+
+       my $subject;
+       if ( $file =~ m/(\w+)/ ) {
+               $_ = $1;
+               $subject =
+                       m/bib/i    ? 'IZBIB' :
+                       m/in[fo]/i ? 'IZDHI' :
+                       m/muz/i    ? 'IZMUZ' :
+                       m/arh/i    ? 'IZARH' :
+                       die "unknown subject: $2";
        }
 
        my $c = $col;
-       $header2col->{'eprintsid'} = $c; $v[$c++] = $eprintsid++;
        $header2col->{'file'} = $c; $v[$c++] = $file;
        $header2col->{'full_path'} = $c; $v[$c++] = $full_path;
+       $header2col->{'subject'} = $c; $v[$c++] = $subject;
 
        my $eprints = $xml;
        while ( $eprints =~ s/<!-- "(.+?)" -->/interpolate($1)/seg ) {
@@ -78,6 +89,7 @@ while(<$tsv>) {
        }
 
        $eprints =~ s{<documents>.+</documents>}{<!-- no documents -->}s if ! $full_path;
+       $eprints =~ s{<subjects>.+</subjects>}{<!-- no subjects -->}s if ! $subject;
 
        print $eprints;
 }