[freeside-commits] freeside/bin cdr.http_and_import, NONE, 1.1 cdr.import, 1.3, 1.4 cdr.sftp_and_import, 1.2, 1.3
Ivan,,,
ivan at wavetail.420.am
Fri Jan 2 17:53:01 PST 2009
Update of /home/cvs/cvsroot/freeside/bin
In directory wavetail.420.am:/tmp/cvs-serv32674/bin
Modified Files:
cdr.import cdr.sftp_and_import
Added Files:
cdr.http_and_import
Log Message:
indosoft CDR format, RT#4425
--- NEW FILE: cdr.http_and_import ---
#!/usr/bin/perl
#
# Usage:
# cdr.http_and_import [ -p prefix ] [ -e extension ] [ -v ] user format URL
#
# -e: file extension, defaults to .csv
# -d: if specified, moves files to the specified folder when done
use strict;
use Getopt::Std;
use WWW::IndexParser;
#use LWP::UserAgent;
use FS::UID qw(adminsuidsetup datasrc dbh);
use FS::cdr;
###
# parse command line
###
use vars qw( $opt_p $opt_e $opt_v );
getopts('p:e:v');
$opt_e ||= 'csv';
#$opt_e = ".$opt_e" unless $opt_e =~ /^\./;
$opt_e =~ s/^\.//;
my $user = shift or die &usage;
adminsuidsetup $user;
# %%%FREESIDE_CACHE%%%
my $cachedir = '/usr/local/etc/freeside/cache.'. datasrc. '/cdrs';
mkdir $cachedir unless -d $cachedir;
my $format = shift or die &usage;
use vars qw( $URL );
$URL = shift or die &usage;
###
# get the file list
###
warn "Retreiving directory listing\n" if $opt_v;
my @files = WWW::IndexParser->new(url => $URL);
###
# import each file
###
foreach my $file ( @files ) {
my $filename = $file->{filename};
if ( $opt_p ) { next unless $filename =~ /^$opt_p/ };
if ( $opt_e ) { next unless $filename =~ /\.$opt_e$/i };
#check and see if we've gotten this file already!!!
#just going to cheat with filenames in the cache for now
if ( -e "$cachedir/$filename" ) {
warn "Already have unprocessed $cachedir/$filename; skipping\n"; # if $opt_v;
next;
}
if ( -e "$cachedir/$filename.DONE" ) {
warn "Already processed $cachedir/$filename; skipping\n" if $opt_v;
next;
}
warn "Downloading $filename\n" if $opt_v;
#get the file
my $ua = LWP::UserAgent->new;
my $response = $ua->get("$URL/$filename");
unless ( $response->is_success ) {
die "Error retreiving $URL/$filename: ". $response->status_line;
}
open(FILE, ">$cachedir/$filename")
or die "can't open $cachedir/$filename: $!";
print FILE $response->content;
close FILE or die "can't close $cachedir/$filename: $!";
warn "Processing $filename\n" if $opt_v;
my $error = FS::cdr::batch_import( {
'file' => "$cachedir/$filename",
'format' => $format,
'params' => { 'cdrbatch' => $filename },
'empty_ok' => 1,
} );
die $error if $error;
close FILE;
rename("$cachedir/$filename", "$cachedir/$filename.DONE");
}
###
# sub
###
sub usage {
"Usage: \n cdr.http_and_import [ -p prefix ] [ -e extension ] [ -v ] user format URL\n";
}
Index: cdr.sftp_and_import
===================================================================
RCS file: /home/cvs/cvsroot/freeside/bin/cdr.sftp_and_import,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cdr.sftp_and_import 2 Jan 2009 22:03:58 -0000 1.2
+++ cdr.sftp_and_import 3 Jan 2009 01:52:58 -0000 1.3
@@ -16,8 +16,8 @@
# parse command line
###
-use vars qw( $opt_e $opt_d $opt_u $opt_v );
-getopts('e:d:u:v');
+use vars qw( $opt_e $opt_d $opt_v );
+getopts('e:d:v');
$opt_e ||= 'csv';
#$opt_e = ".$opt_e" unless $opt_e =~ /^\./;
@@ -64,7 +64,7 @@
my $error = FS::cdr::batch_import( {
'file' => "$cachedir/$filename"
'format' => $format,
- 'cdrbatch' => $filename,
+ 'params' => { 'cdrbatch' => $filename, },
'empty_ok' => 1,
} );
die $error if $error;
Index: cdr.import
===================================================================
RCS file: /home/cvs/cvsroot/freeside/bin/cdr.import,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- cdr.import 2 Jan 2009 22:03:58 -0000 1.3
+++ cdr.import 3 Jan 2009 01:52:58 -0000 1.4
@@ -13,9 +13,12 @@
my $format = shift or die &usage;
+my $file = shift;
+
my $error = FS::cdr::batch_import( {
- 'file' => shift,
+ 'file' => $file,
'format' => $format,
+ 'params' => { 'cdrbatch' => $file },
} );
die $error if $error;
More information about the freeside-commits
mailing list