From 01d5d13ad8fb4ab4b1d833ba8a208830ed81fcd7 Mon Sep 17 00:00:00 2001
From: Gabor Korodi
Date: Tue, 8 Oct 2024 16:55:56 -0400
Subject: [PATCH 1/2] Add an html/jquery example to validate AJAX call against
the Census API
---
census_tract_validator.html | 341 ++++++++++++++++++++++++++++++++++++
1 file changed, 341 insertions(+)
create mode 100644 census_tract_validator.html
diff --git a/census_tract_validator.html b/census_tract_validator.html
new file mode 100644
index 0000000..41110e8
--- /dev/null
+++ b/census_tract_validator.html
@@ -0,0 +1,341 @@
+
+
+
+
+
+
+
+
+
+ Enter a valid address below, and check (via the CensusGeocoder example from Chad Stoughton) if the address is
+ valid for HarvardFCU, or not.
+
+ There are no error checking and no styling! I also did not spend much time on the parsing of the address, so be
+ gentle with it? Please.
+
+
+
+
+ Examples:
+ 77 Massachusetts Ave, cambridge ma 02139
is a supported address
+ 148 winthropshore drive, winthrop, ma 02152
is NOT a supported address
+
+
+
+
+
+
+
+
\ No newline at end of file
From 2cf222c4fe80a7b173fda4e2ce57028b805fb7ac Mon Sep 17 00:00:00 2001
From: Gabor Korodi
Date: Tue, 8 Oct 2024 17:02:46 -0400
Subject: [PATCH 2/2] Add a WordPress plugin to validate an address
---
hvdfcu_census_track_validator.php | 103 +++++++++++++
hvdfcu_census_track_validator.zip | Bin 0 -> 2364 bytes
tracts.csv | 240 ++++++++++++++++++++++++++++++
3 files changed, 343 insertions(+)
create mode 100644 hvdfcu_census_track_validator.php
create mode 100644 hvdfcu_census_track_validator.zip
create mode 100644 tracts.csv
diff --git a/hvdfcu_census_track_validator.php b/hvdfcu_census_track_validator.php
new file mode 100644
index 0000000..57058bc
--- /dev/null
+++ b/hvdfcu_census_track_validator.php
@@ -0,0 +1,103 @@
+ $addr["street"],
+ 'city' => $addr["city"],
+ 'state' => $addr["state"],
+ 'zip' => $addr["zip"],
+ 'benchmark' => 'Public_AR_Census2020', // Use the 2020 Census benchmark
+ 'vintage' => 'Census2020_Census2020', // Census 2020 vintage data
+ 'layers' => 'tract', // Specify layers for census tract
+ 'format' => 'json' // Get the response in JSON format
+ );
+ curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($query_string_data));
+
+ $resp = curl_exec($curl);
+ $info = curl_getinfo($curl);
+ curl_close($curl);
+
+ $r = json_decode($resp);
+ return (count($r->result->addressMatches) > 0) ? $r->result->addressMatches[0]->geographies->{'Census Tracts'}[0]->GEOID : "INVALID";
+}
+
+function getResponse($address)
+{
+ $Content = '';
+ $census_tract_list = explode("\n", file_get_contents(plugin_dir_path(__FILE__) . "tracts.csv"));
+ if (in_array(getCensusTract(parse_address($address)), $census_tract_list)) {
+ $Content .= "Success! Your address is within the list of census tracts we can support
";
+ } else {
+ $Content .= "Unfortunately, that address is not supported by Harvard-FCU
";
+ }
+ return $Content;
+}
+
+function parse_address($address_string)
+{
+ $parts = preg_split('/\s+/', str_replace(',', ' ', $address_string));
+ return [
+ "street" => implode(' ', array_slice($parts, 0, count($parts) - 3)),
+ "city" => $parts[count($parts) - 3],
+ "state" => $parts[count($parts) - 2],
+ "zip" => $parts[count($parts) - 1]
+ ];
+}
+
+$css_styles = "
+
+";
+
+function validate_census_tract($atts)
+{
+
+ $Content = $css_styles;
+ $census_tract_list = explode("\n", file_get_contents(plugin_dir_path(__FILE__) . "tracts.csv"));
+
+ $Content .= '';
+
+ if (isset($_POST['address'])) {
+ $Content .= getResponse($_POST['address']);
+ }
+
+ return $Content;
+}
+
+add_shortcode('validate_census_tract', 'validate_census_tract');
+
+#echo getResponse('77 Massachusetts Ave, cambridge ma 02139');
+#echo getResponse('148 Winthrop Shore Drive, winthrop, ma 02152');
+#echo getResponse('148 Winthrop Shore Drive, cambridge ma 02139');
\ No newline at end of file
diff --git a/hvdfcu_census_track_validator.zip b/hvdfcu_census_track_validator.zip
new file mode 100644
index 0000000000000000000000000000000000000000..cf09d7254f823f05e7b86a36061b51f57c9d9d5b
GIT binary patch
literal 2364
zcmbtWcTm&W7XHzj6ct1WMU)ac1nCQci=ZIAH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BoTLGKWM`YRXAJ!vI
zmuGT&LRvyGg~NWKyxZ*o&YQ-Fn*kQOO=VHp%_?-sRQs0F`>nyRdnM#LS
zS9&ZWexpFr$|c_I$#y*^6pCKBJJRN5_W&hD>X6qd=NVRdJ&oaU^4(F@5Pd(1Z5QKt
zS{4$$tRq_JFN}WhUV$q5?wa;iiyl68?A46;s<4+Rb+hfNTfDF0-lhTq>S`9lp$=;7
zunezqf~9#MhPi*0(>ATWq(RsbYVV;upP7~pn7qNi#6zA
zBj+ki0Kj-A=VSr*@s@J(_WQSPyGGKu?k3T=lKp?_wt31_)n}P=w@yvtTb`!8V;I%k
z`Kcq3sGrjfL_{!c6_9p`#N6D_E}w*2-&f~C1J^G1UF4agmL|YEu~{^6KkyEVjDJCQ
zkqjFJ>dGjgAq@A?k|cjtR&KlEHjIuM8)A4X>;>g-a}DRs9wy>qiyv7GCm+~#jCgeLvq&7I3sJr0^
zV;zPo8hQ~^)5q~mQzQQCujGtZ%D0zl!gv)f25CU&z9?9}9Ze?IToT`4R-gq%F+WJ6
zmX>)iLb1h1ydpmNhUKhW!8p({Tobj|Li7E@gf`SRiAfE<*YaUOJJB{6XPa!9Y$;y7
zm;GC%1J%cna1T1%APFXUX?1@q9OOGzm)yy5wIevZ%}2l9qsCjA@8F~po-^0+JPz{Uj|+FHaq!L~v(b__L>jG)wQGG<
iU%x^oz~5FBHhe~y|D6s-dNj1;SjsaDoOvic`SdTyWII{_
literal 0
HcmV?d00001
diff --git a/tracts.csv b/tracts.csv
new file mode 100644
index 0000000..102a7e2
--- /dev/null
+++ b/tracts.csv
@@ -0,0 +1,240 @@
+tracts
+25009202104
+25009205200
+25009205500
+25009205600
+25009205700
+25009205800
+25009205900
+25009206000
+25009206100
+25009206200
+25009206400
+25009206500
+25009206600
+25009206700
+25009206800
+25009206900
+25009207000
+25009207100
+25009207200
+25009208301
+25009208302
+25017336404
+25017339101
+25017339700
+25017339900
+25017341200
+25017341301
+25017341400
+25017341500
+25017341600
+25017341700
+25017341800
+25017341901
+25017341904
+25017342101
+25017342102
+25017342201
+25017342202
+25017342301
+25017342302
+25017342401
+25017342402
+25017342501
+25017342502
+25017342600
+25017350106
+25017350107
+25017350108
+25017350109
+25017351203
+25017351403
+25017351404
+25017351500
+25017352101
+25017352102
+25017352200
+25017352300
+25017352400
+25017352500
+25017352600
+25017352700
+25017352800
+25017352900
+25017353000
+25017353101
+25017353102
+25017353200
+25017353300
+25017353700
+25017353800
+25017353900
+25017354000
+25017354100
+25017357400
+25017359400
+25017370201
+25017370301
+25017370302
+25017370403
+25017373100
+25021400100
+25021400202
+25025000102
+25025000201
+25025000202
+25025000301
+25025000302
+25025000401
+25025000502
+25025000503
+25025000505
+25025000506
+25025000603
+25025000604
+25025000701
+25025000703
+25025000704
+25025000805
+25025000806
+25025000807
+25025010103
+25025010104
+25025010204
+25025010205
+25025010206
+25025010300
+25025010403
+25025010404
+25025010405
+25025010408
+25025010500
+25025020301
+25025020304
+25025030301
+25025030302
+25025040200
+25025040600
+25025040801
+25025050101
+25025050200
+25025050300
+25025050400
+25025050500
+25025050600
+25025050700
+25025050901
+25025051000
+25025051101
+25025060603
+25025060604
+25025060700
+25025061000
+25025061101
+25025061201
+25025061203
+25025070102
+25025070103
+25025070201
+25025070202
+25025070402
+25025070502
+25025070600
+25025070801
+25025070802
+25025070901
+25025070902
+25025071101
+25025071201
+25025080100
+25025080300
+25025080401
+25025080500
+25025080601
+25025080801
+25025080900
+25025081001
+25025081101
+25025081102
+25025081200
+25025081301
+25025081302
+25025081400
+25025081500
+25025081700
+25025081800
+25025081900
+25025082000
+25025082100
+25025090100
+25025090200
+25025090300
+25025090400
+25025090600
+25025090700
+25025090901
+25025091001
+25025091100
+25025091200
+25025091300
+25025091400
+25025091500
+25025091600
+25025091700
+25025091800
+25025091900
+25025092000
+25025092101
+25025092200
+25025092300
+25025092400
+25025100100
+25025100200
+25025100300
+25025100400
+25025100500
+25025100601
+25025101001
+25025101002
+25025101101
+25025101102
+25025110104
+25025110201
+25025110301
+25025110401
+25025110403
+25025120500
+25025130406
+25025140102
+25025140105
+25025140106
+25025140300
+25025140400
+25025160102
+25025160103
+25025160200
+25025160300
+25025160400
+25025160501
+25025160502
+25025160601
+25025160602
+25025170101
+25025170102
+25025170200
+25025170301
+25025170302
+25025170400
+25025170502
+25025170503
+25025170504
+25025170601
+25025170701
+25025170702
+25025170800
+25025180101
+25025980300
+25025981501
+25025981502
+25025981800
\ No newline at end of file