create marc file
[ferlib2koha.git] / zavrsni-radovi / json2marc.pl
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use autodie;
6 use utf8;
7
8 use JSON;
9 use Data::Dump qw(dump);
10 use MARC::Record;
11
12 open(my $json, '<', 'report_62836_1046_ZavrsniRadovi.json');
13 {
14         undef $/;
15         my $data = <$json>;
16         close($json);
17         $json = decode_json($data);
18 }
19 #warn dump($json->[0]);
20
21 open(my $marc_fh, '>', 'radovi.marc');
22
23 my $stat;
24
25 foreach my $rad ( @$json ) {
26
27         print dump($rad), "\n";
28
29         if ( ! $rad->{naslovhr} ) {
30                 $stat->{no_naslovhr}++;
31                 next;
32         }
33         $stat->{radova}++;
34
35         my $marc = MARC::Record->new;
36         $marc->encoding( 'UTF-8' );
37
38         $marc->add_fields(
39                 grep { ref($_) eq 'ARRAY' }
40                 [ '100', '1', '#', a => $rad->{prezime} . ', ' . $rad->{ime}, g => 'JMBAG:' . $rad->{jmbag} ],
41                 [ '245', '1', '0', a => $rad->{naslovhr} ],
42                 [ '246', '1',
43                         $rad->{nasloven} =~ m/The / ? 4 :
44                         $rad->{nasloven} =~ m/A /   ? 2 : ' ' # FIXME?
45                         , a => $rad->{nasloven}, i => 'Naslov na engleskom: '
46                 ],
47                 $rad->{'brojstranica'} ? [ '300', '#', '#', a => $rad->{'brojstranica'} . ' str. ;', c => '30 cm' ] : '',
48                 [ '502', '#', '#', b => $rad->{studij} . ' studij', c => 'Fakultet elektrotehnike i računarstva u Zagrebu', g => 'smjer: ' . $rad->{smjer}, g => 'šifra smjera: ' . $rad->{sifsmjer}, d => $rad->{datumzavrsetka} ],
49                 $rad->{sazetakhr} ? [ '520', '3', '#', a => 'Sažetak na hrvatskom: ' . $rad->{sazetakhr} ] : '',
50                 $rad->{sazetaken} ? [ '520', '3', '#', a => 'Sažetak na engleskom: ' . $rad->{sazetaken} ] : '',
51                 $rad->{keywords}  ? [ '653', '#', '#', map { ( a => $_ ) } split(/;\s*/, $rad->{keywords}  ) ] : '',
52                 $rad->{keywords_en} ? [ '653', '#', '#', map { ( a => $_ ) } split(/;\s*/, $rad->{keywords_en}) ] : '',
53                 [ '700', '1', '#', a => $rad->{prezmentor} . ', ' . $rad->{imementor}, 4 => 'ths' ],
54                 $rad->{prezmentor2} ? [ '700', '1', '#', a => $rad->{prezmentor2} . ', ' . $rad->{imementor2}, 4 => 'ths' ] : ''
55         );
56
57         print $marc_fh $marc->as_usmarc;
58
59         print $marc->as_formatted, "\n\n"; # FIXME
60
61 #       last if $stat->{radova} == 10; # FIXME
62 }
63
64 print "# stat = ",dump($stat);
65
66 =for import
67
68 ($recordid, $biblioitemnumber) = AddBiblio($marc_record, $framework);
69
70 =cut