[freeside-commits] freeside/httemplate/misc xmlhttp-cust_main-censustract.html, 1.3.4.1, 1.3.4.2
Mark Wells
mark at wavetail.420.am
Fri Jan 13 02:17:57 PST 2012
Update of /home/cvs/cvsroot/freeside/httemplate/misc
In directory wavetail.420.am:/tmp/cvs-serv19885/httemplate/misc
Modified Files:
Tag: FREESIDE_2_3_BRANCH
xmlhttp-cust_main-censustract.html
Log Message:
missing file from #15381
Index: xmlhttp-cust_main-censustract.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/misc/xmlhttp-cust_main-censustract.html,v
retrieving revision 1.3.4.1
retrieving revision 1.3.4.2
diff -u -w -d -r1.3.4.1 -r1.3.4.2
--- xmlhttp-cust_main-censustract.html 12 Aug 2011 21:57:43 -0000 1.3.4.1
+++ xmlhttp-cust_main-censustract.html 13 Jan 2012 10:17:55 -0000 1.3.4.2
@@ -1,117 +1,14 @@
<% objToJson($return) %>
<%init>
-my $DEBUG = 0;
-
-my $url='http://www.ffiec.gov/Geocode/default.aspx';
-
-my $sub = $cgi->param('sub');
-
-my $return = {};
-my $error = '';
-
-use LWP::UserAgent;
-use HTTP::Request;
-use HTTP::Request::Common qw( GET POST );
-use HTML::TokeParser;
-
-if ( $sub eq 'censustract' ) {
-
my %arg = $cgi->param('arg');
- warn join('', map "$_: $arg{$_}\n", keys %arg )
- if $DEBUG;
-
- my $ua = new LWP::UserAgent;
- my $res = $ua->request( GET( $url ) );
-
- warn $res->as_string
- if $DEBUG > 1;
-
- unless ($res->code eq '200') {
-
- $error = $res->message;
-
- } else {
-
- my $content = $res->content;
- my $p = new HTML::TokeParser \$content;
- my $viewstate;
- my $eventvalidation;
- while (my $token = $p->get_tag('input') ) {
- if ($token->[1]->{name} eq '__VIEWSTATE') {
- $viewstate = $token->[1]->{value};
- }
- if ($token->[1]->{name} eq '__EVENTVALIDATION') {
- $eventvalidation = $token->[1]->{value};
- }
- last if $viewstate && $eventvalidation;
- }
-
- unless ($viewstate && $eventvalidation ) {
-
- $error = "either no __VIEWSTATE or __EVENTVALIDATION found";
-
- } else {
-
- my($zip5, $zip4) = split('-',$arg{zip});
-
- $arg{year} ||= '2011';
- #ugh workaround a mess at ffiec
- $arg{year} = " $arg{year}" if $arg{year} ne '2011';
- my @ffiec_args = (
- __VIEWSTATE => $viewstate,
- __EVENTVALIDATION => $eventvalidation,
- ddlbYear => $arg{year},
- ddlbYear => '2011', #' 2009',
- txtAddress => $arg{address},
- txtCity => $arg{city},
- ddlbState => $arg{state},
- txtZipCode => $zip5,
- btnSearch => 'Search',
- );
- warn join("\n", @ffiec_args )
- if $DEBUG;
-
- push @{ $ua->requests_redirectable }, 'POST';
- $res = $ua->request( POST( $url, \@ffiec_args ) );
- warn $res->as_string
- if $DEBUG > 1;
-
- unless ($res->code eq '200') {
-
- $error = $res->message;
-
- } else {
-
- my @id = qw( MSACode StateCode CountyCode TractCode );
- $content = $res->content;
- warn $res->content if $DEBUG > 1;
- $p = new HTML::TokeParser \$content;
- my $prefix = 'UcGeoResult11_lb';
- my $compare =
- sub { my $t=shift; scalar( grep { lc($t) eq lc("$prefix$_")} @id ) };
-
- while (my $token = $p->get_tag('span') ) {
- next unless ( $token->[1]->{id} && &$compare( $token->[1]->{id} ) );
- $token->[1]->{id} =~ /^$prefix(\w+)$/;
- $return->{lc($1)} = $p->get_trimmed_text("/span");
+my $year = delete($arg{'year'});
+my $return = get_censustract(\%arg, $year);
+if ( $return =~ /^\d/ ) {
+ $return = { 'censustract' => $return };
}
-
- $error = "No census tract found" unless $return->{tractcode};
- $return->{tractcode} .= ' '
- unless $error || $JSON::VERSION >= 2; #broken JSON 1 workaround
-
- } #unless ($res->code eq '200')
-
- } #unless ($viewstate)
-
- } #unless ($res->code eq '200')
-
- $error = "FFIEC Geocoding error: $error" if $error;
- $return->{'error'} = $error;
-
- $return;
-
+else {
+ $return = { 'error' => $return };
}
</%init>
More information about the freeside-commits
mailing list