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

(-)a/misc/export2ebsco.pl (-1 / +136 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
my $result = GetOptions(
48
    'h|help'         => \$want_help
49
);
50
	
51
binmode( STDOUT, ":utf8" );
52
	
53
if ( not $result or $want_help ) {
54
    usage();
55
}
56
57
unless ( chdir '/tmp' ) {
58
    croak 'Unable to cd to /tmp';
59
}
60
61
my $filename = get_filename();
62
63
write_file($filename);
64
65
transfer_file($filename);
66
67
sub write_file {
68
    my $export_filename = shift;
69
    my $dbh             = C4::Context->dbh;
70
71
    my $query =
72
#      'SELECT distinct biblioitems.biblionumber FROM biblioitems WHERE biblionumber >0 ';
73
       'SELECT distinct biblioitems.biblionumber FROM biblioitems LEFT JOIN items USING (biblioitemnumber) WHERE biblioitems.biblionumber >0 ';
74
75
    my $sth = $dbh->prepare($query);
76
    $sth->execute();
77
78
    open my $fh, '>:encoding(utf8)', $export_filename
79
      or croak "Cannot open $export_filename : $!";
80
81
    while ( my ($biblionumber) = $sth->fetchrow_array ) {
82
#        my $marc_record = GetMarcBiblio($biblionumber, 1);
83
         my $marc_record = GetMarcBiblio({ biblionumber => $biblionumber,embed_items => 1});
84
        if ($marc_record) {
85
            print {$fh} $marc_record->as_usmarc();
86
        }
87
    }
88
    if ( !close $fh ) {
89
        croak "Writing to $export_filename failed on close";
90
    }
91
    return;
92
}
93
94
sub get_filename {
95
    my @abbr  = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
96
    my @tm    = localtime();
97
    my $month = $tm[4];
98
    my $year  = $tm[5] - 100;
99
    my $name  = 'INSERT FILE NAME HERE' . $abbr[$month] . $year;
100
101
    $name .= '.mrc';
102
103
    # will need to add a directory & unique date id to file
104
    return $name;
105
}
106
107
sub transfer_file {
108
    my $marc_file = shift;
109
    my $remote    = 'ftp.epnet.com';
110
    my $username  = q(INSERT USERNAME HERE);
111
    my $password = q(INSERT PASSWORD HERE);
112
113
    my $ftp = Net::FTP->new( $remote, Passive => 1, Debug => 0 )
114
      or croak "Cannot connect to epnet: $@";
115
116
  $ftp->login( $username, $password )
117
      or croak 'Cannot login to Epnet ', $ftp->message;
118
    $ftp->cwd("full")
119
          or die "Cannot change working directory ", $ftp->message;
120
    $ftp->put($marc_file);
121
  
122
   $ftp->quit;
123
124
    return;
125
}
126
=head1 NAME
127
128
export2collectionhq.pl
129
130
=head1 SYNOPSIS
131
132
  export2collectionhq.pl
133
134
=head1 DESCRIPTION
135
136
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