diff options
author | ivan <ivan> | 2009-01-03 01:52:59 +0000 |
---|---|---|
committer | ivan <ivan> | 2009-01-03 01:52:59 +0000 |
commit | 0da7ecb92ccd671c47cb7fd4d04560cc80d4b520 (patch) | |
tree | 2c40a0ab1d7703806d5a85f1b248d219238eabd0 /bin | |
parent | 1d5f7cb129a7fade6ef9283977b2781ece183797 (diff) |
indosoft CDR format, RT#4425
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cdr.http_and_import | 108 | ||||
-rw-r--r-- | bin/cdr.import | 5 | ||||
-rwxr-xr-x | bin/cdr.sftp_and_import | 6 |
3 files changed, 115 insertions, 4 deletions
diff --git a/bin/cdr.http_and_import b/bin/cdr.http_and_import new file mode 100755 index 000000000..5637fa526 --- /dev/null +++ b/bin/cdr.http_and_import @@ -0,0 +1,108 @@ +#!/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"; +} + diff --git a/bin/cdr.import b/bin/cdr.import index b2e8d9127..a17417b85 100644 --- a/bin/cdr.import +++ b/bin/cdr.import @@ -13,9 +13,12 @@ adminsuidsetup $user; 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; diff --git a/bin/cdr.sftp_and_import b/bin/cdr.sftp_and_import index 57d4e871e..79e743f39 100755 --- a/bin/cdr.sftp_and_import +++ b/bin/cdr.sftp_and_import @@ -16,8 +16,8 @@ use FS::cdr; # 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 @@ foreach my $file ( @$ls ) { my $error = FS::cdr::batch_import( { 'file' => "$cachedir/$filename" 'format' => $format, - 'cdrbatch' => $filename, + 'params' => { 'cdrbatch' => $filename, }, 'empty_ok' => 1, } ); die $error if $error; |