This updates the code to support the new divisionsByAddress API as noted in #1 since the representatives API is being deprecated.
This commit is contained in:
parent
f5f6fd8ef0
commit
3a0092fa0e
@ -203,51 +203,57 @@ foreach my $file (@files) {
|
|||||||
if ( $searchType eq "google" ) {
|
if ( $searchType eq "google" ) {
|
||||||
|
|
||||||
# Delegate District Query
|
# Delegate District Query
|
||||||
my $queryDelegateDistrict =
|
my $queryDistricts =
|
||||||
"https://www.googleapis.com/civicinfo/v2/representatives?includeOffices=true&levels=administrativeArea1&roles=legislatorLowerBody&"
|
"https://www.googleapis.com/civicinfo/v2/divisionsByAddress?"
|
||||||
. "key=${googleApiKey}&"
|
. "key=${googleApiKey}&"
|
||||||
. "address=${address}";
|
. "address=${address}";
|
||||||
|
|
||||||
sleep 2;
|
sleep 2;
|
||||||
my $res = $curl->get($queryDelegateDistrict);
|
my $res = $curl->get($queryDistricts);
|
||||||
my $content = decode_json( $res->content );
|
my $content = decode_json( $res->content );
|
||||||
|
|
||||||
#print Dumper($content);
|
my $divisions = $content->{'divisions'};
|
||||||
|
my $lowercase_state = lc($state);
|
||||||
|
|
||||||
my $divisionNumber =
|
# Pre-check for specific patterns
|
||||||
( ( keys %{ $content->{divisions} } )[0] );
|
my $has_match = 0; # Flag to track if a match is found
|
||||||
if ( $divisionNumber && $state eq "WV" ) {
|
foreach my $key ( keys %{$divisions} ) {
|
||||||
my @divisionNumber = split /:/, $divisionNumber;
|
if ( $key =~ /state:$lowercase_state\/sld[ul]:\d+/ )
|
||||||
|
{
|
||||||
|
$has_match = 1;
|
||||||
|
last; # Exit loop early if a match is found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# print Dumper($divisions);
|
||||||
|
|
||||||
|
if ( $divisions && $state eq "WV" && $has_match ) {
|
||||||
|
;
|
||||||
|
|
||||||
|
foreach my $key ( keys %{$divisions} ) {
|
||||||
|
if ( $key =~
|
||||||
|
/ocd-division\/country:us\/state:$lowercase_state\/sldu:(\d+)/
|
||||||
|
)
|
||||||
|
{
|
||||||
|
my $senateDistrictNumber =
|
||||||
|
$1; # Capture the number for sldu
|
||||||
|
$csv .= "$senateDistrictNumber,";
|
||||||
|
}
|
||||||
|
elsif ( $key =~
|
||||||
|
/ocd-division\/country:us\/state:$lowercase_state\/sldl:(\d+)/
|
||||||
|
)
|
||||||
|
{
|
||||||
|
my $houseDistrictNumber =
|
||||||
|
$1; # Capture the number for sldl
|
||||||
|
$csv .= "$houseDistrictNumber,";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#print $divisionNumber[3] . "\n";
|
|
||||||
$csv .= "$divisionNumber[3],";
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$csv .= ",";
|
$csv .= ",";
|
||||||
}
|
|
||||||
|
|
||||||
# Senate District Query
|
|
||||||
my $querySenateDistrict =
|
|
||||||
"https://www.googleapis.com/civicinfo/v2/representatives?includeOffices=true&levels=administrativeArea1&roles=legislatorUpperBody&"
|
|
||||||
. "key=${googleApiKey}&"
|
|
||||||
. "address=${address}";
|
|
||||||
|
|
||||||
sleep 2;
|
|
||||||
$res = $curl->get($querySenateDistrict);
|
|
||||||
$content = decode_json( $res->content );
|
|
||||||
|
|
||||||
# print Dumper($content);
|
|
||||||
$divisionNumber =
|
|
||||||
( ( keys %{ $content->{divisions} } )[0] );
|
|
||||||
if ( $divisionNumber && $state eq "WV" ) {
|
|
||||||
my @divisionNumber = split /:/, $divisionNumber;
|
|
||||||
|
|
||||||
#print $divisionNumber[3] . "\n";
|
|
||||||
$csv .= "$divisionNumber[3],";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$csv .= ",";
|
$csv .= ",";
|
||||||
}
|
}
|
||||||
|
|
||||||
$csv .= "$leagueId,";
|
$csv .= "$leagueId,";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user