/[webpac]/trunk/tools/phpmylib2marc.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/tools/phpmylib2marc.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 208 - (show annotations)
Sun Feb 1 15:57:17 2004 UTC (17 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 2664 byte(s)
Script which will read PhpMyLibrary (http://phpmylibrary.sourceforge.net/)
database and dump MARC file for import in webpac

1 #!/usr/bin/perl -w
2 #
3 # This script will try (hard) to convert database from
4 # PhpMyLibrary (http://phpmylibrary.sourceforge.net/) back
5 # to MARC format
6 #
7 # 2003-01-31 Dobrica Pavlinusic <dpavlin@rot13.org>
8 #
9 # This script is written for WebPac project available at
10 # http://webpac.sourceforge.net/
11 #
12 # MARC file format documentation is taken from
13 # http://www.ariadne.ac.uk/issue7/marc/
14 #
15 #
16
17 use DBI;
18 use strict;
19 use Getopt::Long;
20
21 my $database = "postnuke";
22 my $host = "localhost";
23 my $user = "root";
24 my $passwd = "";
25
26 my $usage = 0;
27
28 my $result = GetOptions(
29 "database=s" => \$database,
30 "host=s" => \$host,
31 "user=s" => \$user,
32 "password=s" => \$passwd,
33 "help!" => \$usage,
34 );
35
36 if ($usage) {
37 print qq{usage: $0 [--database="$database" --host="$host" --user="$user" --password="$passwd"] > file.marc\n
38 This script will convert PhpMyLibrary database to standard UNIMARC format\n};
39 exit 1;
40 }
41
42 my $dsn = "DBI:mysql:database=$database;host=$host";
43 my $dbh = DBI->connect($dsn, $user, $passwd, {'RaiseError' => 1});
44
45 # UNIMARC leader format
46 my $leader_fmt = qq{%05diam0 22%05d 45 };
47
48
49 my $sth = $dbh->prepare("SELECT marc FROM tblbib");
50 $sth->execute();
51 while (my $row = $sth->fetchrow_hashref()) {
52 my $marc = $row->{'marc'};
53
54 my $real_len = length($marc);
55
56 # fix PhpMyLibrary MARC (why do I have to do this? It's MARC,
57 # for gaddem sake!!!
58
59 # Byte Name
60 # ---- ----
61 # 0-4 Record Length
62 # 5 Status (n=new, c=corrected and d=deleted)
63 # 6 Type of Record (a=printed material)
64 # 7 Bibliographic Level (m=monograph)
65 # 8-9 Blanks
66 # 10 Indictator count (2 for monographs)
67 # 11 Subfield code count (2 - 0x1F+subfield code itself)
68 # 12-16 Base address of data
69 # 17 Encoding level (blank=full level, 1=sublevel 1, 2=sublevel 2,
70 # 3=sublevel 3)
71 # 18 Descriptive Cataloguing Form (blank=record is full ISBD,
72 # n=record is in non-ISBD format, i=record is in
73 # an incomplete ISBD format)
74 # 19 Blank
75 # 20 Length of length field in directory (always 4 in UNIMARC)
76 # 21 Length of Starting Character Position in directory (always
77 # 5 in UNIMARC)
78 # 22 Length of implementation defined portion in directory (always
79 # 0 in UNIMARC)
80 # 23 Blank
81 #
82 # |0 4|5 89 |12 16|1n 450 |
83 # (xxxxx)nam 22(.....) 450 <---
84 $marc =~ m/^(.....)......(.....)polerioj/ || die "record: '$marc' unparsable!";
85 my ($reclen,$base_addr) = ($1,$2);
86 my $leader = sprintf($leader_fmt,length($marc)+1,$base_addr);
87
88 print $leader . substr($marc,24).chr(29);
89 }
90 $sth->finish();
91 $dbh->disconnect();

Properties

Name Value
cvs2svn:cvs-rev 1.1
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26