Skip to content

Commit

Permalink
Merge pull request #163 from cfpb/fix/add-new-fips-to-update-data
Browse files Browse the repository at this point in the history
Fix/add new FIPS codes and update data
  • Loading branch information
wpears committed Dec 28, 2023
2 parents 59cfcf7 + fbbf381 commit 23d8788
Show file tree
Hide file tree
Showing 7 changed files with 16,197 additions and 3,238 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/

# Distribution / packaging
.Python
.python-version
env/
bin/
build/
Expand Down
3,238 changes: 3,237 additions & 1 deletion countylimits/data/base_data/county_FIPS.csv

Large diffs are not rendered by default.

3,235 changes: 3,235 additions & 0 deletions countylimits/data/base_data/county_limit_data_flat_2023.csv

Large diffs are not rendered by default.

3,238 changes: 3,238 additions & 0 deletions countylimits/data/base_data/forward_limits_2023.csv

Large diffs are not rendered by default.

3,238 changes: 3,238 additions & 0 deletions countylimits/data/base_data/gse_limits_2023.csv

Large diffs are not rendered by default.

6,467 changes: 3,234 additions & 3,233 deletions countylimits/data/county_limit_data_latest.csv

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions countylimits/data_collection/gather_county_data.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import datetime
import os
import pytz
from collections import OrderedDict
from csv import DictReader
from csv import writer as Writer

import requests

from django.utils import timezone


TZ = pytz.timezone("US/Eastern")
AWARE_NOW = timezone.now().astimezone(TZ)
ERROR_MSG = "Script failed to process all files."
API_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
DATA_DIR = "{}/data".format(API_DIR)
Expand Down Expand Up @@ -135,7 +139,7 @@ def get_chums_data(year=None):
Files are available manually
at https://www.hud.gov/pub/chums/file_layouts.html
"""
year = year or datetime.date.today().year + 1
year = year or AWARE_NOW.year + 1
msg = ""
try:
fha = download_datafile(CHUMS_FHA_URL.format(year)).split("\r\n")
Expand Down Expand Up @@ -171,6 +175,12 @@ def get_chums_data(year=None):
"`python manage.py load_county_limits "
"data/county_limit_data_latest.csv --confirm=y`"
)
except Exception:
return "{}\n{}".format(ERROR_MSG, msg)
except KeyError as e:
return (
f"A KeyError ({e}) occurred while processing the data. "
"If the error is a five-digit number, this could be caused by "
"the introduction of a new county FIPS code."
)
except Exception as e:
return f"{ERROR_MSG} Error: {e}\n{msg}"
return msg

0 comments on commit 23d8788

Please sign in to comment.