View | Details | Raw Unified | Return to bug 25246
Collapse All | Expand All

(-)a/misc/export2ebsco.pl (-1 / +132 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/env perl
2
3
#
4
# This file is part of Koha.
5
#
6
# Koha is free software; you can redistribute it and/or modify it under the
7
# terms of the GNU General Public License as published by the Free Software
8
# Foundation; either version 3 of the License, or (at your option) any later
9
# version.
10
#
11
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
12
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License along with
16
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
17
# Suite 330, Boston, MA  02111-1307 USA
18
19
use strict;
20
use warnings;
21
use FindBin;
22
use lib "$FindBin::Bin/../..";
23
use Carp;
24
use C4::Context;
25
use C4::Auth;
26
use C4::Output;
27
use C4::Biblio;    # GetMarcBiblio GetXmlBiblio
28
use C4::Koha;      # GetItemTypes
29
use Net::FTP;
30
use Getopt::Long;
31
use Pod::Usage;
32
33
sub usage {
34
    pod2usage( -verbose => 2 );
35
    exit;
36
}
37
38
$| = 1;
39
40
# command-line parameters
41
 my $want_help   = 0;
42
#
43
 my $result = GetOptions(
44
  'h|help'         => \$want_help
45
);
46
47
binmode( STDOUT, ":encoding(utf8)" );
48
49
if ( not $result or $want_help ) {
50
    usage();
51
}
52
53
unless ( chdir '/tmp' ) {
54
    croak 'Unable to cd to /tmp';
55
}
56
57
my $filename = get_filename();
58
59
write_file($filename);
60
61
transfer_file($filename);
62
63
sub write_file {
64
    my $export_filename = shift;
65
    my $dbh             = C4::Context->dbh;
66
67
    my $query =
68
#      'SELECT distinct biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ';
69
       'SELECT distinct biblioitems.biblionumber FROM biblioitems LEFT JOIN items USING (biblioitemnumber) WHERE biblioitems.biblionumber >0 ';
70
71
    my $sth = $dbh->prepare($query);
72
    $sth->execute();
73
74
    open my $fh, '>:encoding(utf8)', $export_filename
75
      or croak "Cannot open $export_filename : $!";
76
77
    while ( my ($biblionumber) = $sth->fetchrow_array ) {
78
#        my $marc_record = GetMarcBiblio($biblionumber, 1);
79
         my $marc_record = GetMarcBiblio({ biblionumber => $biblionumber,embed_items => 1});
80
        if ($marc_record) {
81
            print {$fh} $marc_record->as_usmarc();
82
        }
83
    }
84
    if ( !close $fh ) {
85
        croak "Writing to $export_filename failed on close";
86
    }
87
    return;
88
}
89
90
sub get_filename {
91
    my @abbr  = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
92
    my @tm    = localtime();
93
    my $month = $tm[4];
94
    my $year  = $tm[5] - 100;
95
    my $name  = 'INSERT FILE NAME HERE' . $abbr[$month] . $year;
96
97
    $name .= '.mrc';
98
99
    # will need to add a directory & unique date id to file
100
    return $name;
101
}
102
103
sub transfer_file {
104
    my $marc_file = shift;
105
    my $remote    = 'ftp.epnet.com';
106
    my $username  = q(INSERT USERNAME HERE);
107
    my $password = q(INSERT PASSWORD HERE);
108
109
    my $ftp = Net::FTP->new( $remote, Passive => 1, Debug => 0 )
110
      or croak "Cannot connect to epnet: $@";
111
112
  $ftp->login( $username, $password )
113
      or croak 'Cannot login to Epnet ', $ftp->message;
114
    $ftp->cwd("full")
115
          or die "Cannot change working directory ", $ftp->message;
116
    $ftp->put($marc_file);
117
118
   $ftp->quit;
119
120
    return;
121
}
122
=head1 NAME
123
124
export2ebsco.pl
125
126
=head1 SYNOPSIS
127
128
  export2ebsco.pl
129
130
=head1 DESCRIPTION
131
132
This script exports bibliographic data to EBSCO EDS. It is imperative that the ifilename, username and password are all edited in the script for successful transfer to EBSCO.

Return to bug 25246