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
@ -120,17 +120,17 @@ foreach my $file (@files) {
|
||||
|
||||
# Local League file processing
|
||||
# League ID is in column 11
|
||||
( $leagueId = $fields[11] ) =~ s/"//g; # League ID
|
||||
( $phone = $fields[4] ) =~ s/"//g; # Phone
|
||||
( $email = $fields[3] ) =~ s/"//g; # Email
|
||||
( $leagueId = $fields[11] ) =~ s/"//g; # League ID
|
||||
( $phone = $fields[4] ) =~ s/"//g; # Phone
|
||||
( $email = $fields[3] ) =~ s/"//g; # Email
|
||||
( $joinDate = $fields[13] ) =~ s/"//g; # Join Date
|
||||
}
|
||||
else {
|
||||
# Members At Large (MAL) file processing
|
||||
# League ID is assumed to be WV000 for all MALs
|
||||
$leagueId = "WV000"; # Default for MALs
|
||||
( $phone = $fields[3] ) =~ s/"//g; # Phone
|
||||
( $email = $fields[4] ) =~ s/"//g; # Email
|
||||
$leagueId = "WV000"; # Default for MALs
|
||||
( $phone = $fields[3] ) =~ s/"//g; # Phone
|
||||
( $email = $fields[4] ) =~ s/"//g; # Email
|
||||
( $joinDate = $fields[10] ) =~ s/"//g; # Join Date
|
||||
}
|
||||
( my $firstName = $fields[0] ) =~ s/"//g; # First Name
|
||||
@ -203,51 +203,57 @@ foreach my $file (@files) {
|
||||
if ( $searchType eq "google" ) {
|
||||
|
||||
# Delegate District Query
|
||||
my $queryDelegateDistrict =
|
||||
"https://www.googleapis.com/civicinfo/v2/representatives?includeOffices=true&levels=administrativeArea1&roles=legislatorLowerBody&"
|
||||
my $queryDistricts =
|
||||
"https://www.googleapis.com/civicinfo/v2/divisionsByAddress?"
|
||||
. "key=${googleApiKey}&"
|
||||
. "address=${address}";
|
||||
|
||||
sleep 2;
|
||||
my $res = $curl->get($queryDelegateDistrict);
|
||||
my $res = $curl->get($queryDistricts);
|
||||
my $content = decode_json( $res->content );
|
||||
|
||||
#print Dumper($content);
|
||||
my $divisions = $content->{'divisions'};
|
||||
my $lowercase_state = lc($state);
|
||||
|
||||
my $divisionNumber =
|
||||
( ( keys %{ $content->{divisions} } )[0] );
|
||||
if ( $divisionNumber && $state eq "WV" ) {
|
||||
my @divisionNumber = split /:/, $divisionNumber;
|
||||
# Pre-check for specific patterns
|
||||
my $has_match = 0; # Flag to track if a match is found
|
||||
foreach my $key ( keys %{$divisions} ) {
|
||||
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 {
|
||||
$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 .= "$leagueId,";
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user