Skip to content

Commit dd1fe1e

Browse files
committed
shared function for special facilities
Signed-off-by: John Seekins <[email protected]>
1 parent 94b83d3 commit dd1fe1e

File tree

4 files changed

+33
-26
lines changed

4 files changed

+33
-26
lines changed

ice_scrapers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
repair_locality, # noqa: F401
132132
repair_street, # noqa: F401
133133
repair_zip, # noqa: F401
134+
special_facilities, # noqa: F401
134135
update_facility, # noqa: F401
135136
)
136137
from .facilities_scraper import scrape_facilities # noqa: F401,E402

ice_scrapers/facilities_scraper.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
repair_locality,
88
repair_street,
99
repair_zip,
10+
special_facilities,
1011
update_facility,
1112
)
1213
from schemas import facility_schema
@@ -21,19 +22,6 @@
2122
base_scrape_url = "https://www.ice.gov/detention-facilities"
2223

2324

24-
def _special_facilities(facility: dict) -> dict:
25-
match facility["name"]:
26-
case "Naval Station Guantanamo Bay (JTF Camp Six and Migrant Ops Center Main A)":
27-
facility["address"]["country"] = "Cuba"
28-
facility["address"]["administrative_area"] = "FPO"
29-
facility["address"]["locality"] = "FPO"
30-
facility["address"]["postal_code"] = "34009"
31-
facility["address"]["street"] = "AVENUE C PSC 1005 BOX 55"
32-
case _:
33-
pass
34-
return facility
35-
36-
3725
def scrape_facilities(facilities_data: dict) -> dict:
3826
"""Scrape all ICE detention facility data from all discovered pages"""
3927
start_time = time.time()
@@ -50,7 +38,7 @@ def scrape_facilities(facilities_data: dict) -> dict:
5038
logger.debug("Found %s facilities on page %s", len(facilities), page_num + 1)
5139
time.sleep(1) # Be respectful to the server
5240
for facility in facilities:
53-
facility = _special_facilities(facility)
41+
facility = special_facilities(facility)
5442
addr = facility["address"]
5543
street, cleaned = repair_street(addr["street"], addr["locality"])
5644
if cleaned:

ice_scrapers/spreadsheet_load.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
repair_locality,
1616
repair_street,
1717
repair_zip,
18+
special_facilities,
1819
)
1920
from typing import Tuple
2021
from utils import (
@@ -72,17 +73,6 @@ def _download_sheet(keep_sheet: bool = True) -> Tuple[polars.DataFrame, str]:
7273
return df, actual_link
7374

7475

75-
def _special_rows(row: dict) -> dict:
76-
match row["name"]:
77-
case "JTF CAMP SIX":
78-
row["address"]["country"] = "Cuba"
79-
row["address"]["administrative_area"] = "FPO"
80-
row["name"] = "Naval Station Guantanamo Bay (JTF Camp Six and Migrant Ops Center Main A)"
81-
case _:
82-
pass
83-
return row
84-
85-
8676
def load_sheet(keep_sheet: bool = True) -> dict:
8777
df, sheet_url = _download_sheet(keep_sheet)
8878
"""Convert the detentionstats sheet data into something we can update our facilities with"""
@@ -110,7 +100,7 @@ def load_sheet(keep_sheet: bool = True) -> dict:
110100
details["address"]["postal_code"] = zcode
111101
details["address"]["street"] = street
112102
details["name"] = row["Name"]
113-
details = _special_rows(details)
103+
details = special_facilities(details)
114104
full_address = ",".join(
115105
[
116106
details["address"]["street"],

ice_scrapers/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,34 @@
77
)
88

99

10+
def special_facilities(facility: dict) -> dict:
11+
"""
12+
Some very specific facilities have unique fixes
13+
that are hard to fit into our normal repair_* pattern.
14+
15+
Please don't expand this function unless it's necessary
16+
"""
17+
match facility["name"]:
18+
case "Naval Station Guantanamo Bay (JTF Camp Six and Migrant Ops Center Main A)":
19+
"""
20+
First special case? JTF Camp Six is purely a mess.
21+
While we work on getting a consistent address for this facility,
22+
we'll need to make the two records converge.
23+
"""
24+
facility["address"]["country"] = "Cuba"
25+
facility["address"]["administrative_area"] = "FPO"
26+
facility["address"]["locality"] = "FPO"
27+
facility["address"]["postal_code"] = "34009"
28+
facility["address"]["street"] = "AVENUE C PSC 1005 BOX 55"
29+
case "JTF CAMP SIX":
30+
facility["address"]["country"] = "Cuba"
31+
facility["address"]["administrative_area"] = "FPO"
32+
facility["name"] = "Naval Station Guantanamo Bay (JTF Camp Six and Migrant Ops Center Main A)"
33+
case _:
34+
pass
35+
return facility
36+
37+
1038
def repair_street(street: str, locality: str = "") -> Tuple[str, bool]:
1139
"""Generally, we'll let the spreadsheet win arguments just to be consistent"""
1240
street_filters = [

0 commit comments

Comments
 (0)