[freeside-commits] freeside/bin fetch_and_expand_taxes, NONE, 1.1.2.2 reassemble_taxes, NONE, 1.1.2.2

Jeff Finucane,420,, jeff at wavetail.420.am
Mon Dec 21 06:37:25 PST 2009


Update of /home/cvs/cvsroot/freeside/bin
In directory wavetail.420.am:/tmp/cvs-serv22045/bin

Added Files:
      Tag: FREESIDE_1_9_BRANCH
	fetch_and_expand_taxes reassemble_taxes 
Log Message:
move cch conf into database and add a couple small tools for processing updates more manually

--- NEW FILE: fetch_and_expand_taxes ---
#!/usr/bin/perl -w

use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use FS::UID qw(adminsuidsetup);
use FS::Conf;

my $user = shift or die &usage;
my $dir = shift or die &usage;


adminsuidsetup $user;

my $conf = new FS::Conf;

chdir $dir or die "can't change to $dir: $!\n";

die "direct download of tax data not enabled\n"
  unless $conf->exists('taxdatadirectdownload');
my ( $urls, $username, $secret, $states ) =
  $conf->config('taxdatadirectdownload');
die "No tax download URL provided.  ".
    "Did you set the taxdatadirectdownload configuration value?\n"
  unless $urls;

my $ua = new LWP::UserAgent;
  foreach my $url (split ',', $urls) {
  my @name = split '/', $url;  #somewhat restrictive
  my $name = pop @name;
  $name =~ /(.*)/; # untaint that which we trust;
  $name = $1;

  open my $taxfh, ">$name" or die "Can't open $name: $!\n";

  my $res = $ua->request(
    new HTTP::Request( GET => $url),
    sub { #my ($data, $response_object) = @_;
          print $taxfh $_[0] or die "Can't write to $dir.new/$name: $!\n";
    },
  );
  die "download of $url failed: ". $res->status_line
    unless $res->is_success;
  close $taxfh;
  $secret =~ /(.*)/; # untaint that which we trust;
  $secret = $1;
  system('unzip', "-P", $secret, $name) == 0
    or die "unzip -P $secret $name failed";
}

sub usage {
  die "Usage:\n\n  fetch_and_expand_taxes user dir\n";
}


--- NEW FILE: reassemble_taxes ---
#!/usr/bin/perl -w

use strict;
use FS::UID qw(adminsuidsetup);
use FS::Conf;

my $user = shift or die &usage;
my $dir = shift or die &usage;


adminsuidsetup $user;

my $conf = new FS::Conf;

chdir $dir or die "can't change to $dir: $!\n";
die "pmzclfull.zip already exists\n" if -f 'pmzclfull.zip';

die "direct download of tax data not enabled\n"
  unless $conf->exists('taxdatadirectdownload');
my ( $urls, $username, $secret, $states ) =
  $conf->config('taxdatadirectdownload');
die "No tax download URL provided.  ".
    "Did you set the taxdatadirectdownload configuration value?\n"
  unless $urls;

my @filelist = qw( code.dbf detail.dbf geocode.dbf npanxx.dbf plus4.dbf
  txmatrix.dbf zip.dbf );

system('zip', "-P", $secret, 'pmzclfull.zip', @filelist) == 0
  or die "zip failed\n";

sub usage {
  die "Usage:\n\n  reassemble_taxes user dir\n";
}




More information about the freeside-commits mailing list