-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate the gathering of county limit data #108
Conversation
This annual task involves downloading fixed-width files from HUD, formatting them, combining them and producing a final file that can be loaded into the owning-a-home API. Included here are a script to automate that process and a management command to run the script.
…nd-alone instance with csvkit installed or in a cfgov environment with no csvkit
return final_data | ||
|
||
|
||
def get_chums_data(year=(datetime.date.today().year + 1)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be an edge case, but be careful assigning default values like this. The datetime.date.today().year
call happens only once, when the module gets imported, not every time the method gets called with no year
argument. It's unlikely to happen, but I have done something similar in the path with
def do_something_based_on_date(date=datetime.date.today()):
...
and then spent a bunch of time debugging why my jobs that happened to run around midnight gave strange results. A safer pattern might be to do something like
def get_chums_data(year=None):
year = year or datetime.date.today().year
...
"Data can be loaded with this command: \n" | ||
"`python manage.py load_county_limits " | ||
"data/county_limit_data_latest.csv --confirm=y`") | ||
except: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From PEP8:
A bare except: clause will catch SystemExit and KeyboardInterrupt exceptions, making it harder to interrupt a program with Control-C, and can disguise other problems. If you want to catch all exceptions that signal program errors, use except Exception: (bare except is equivalent to except BaseException: ).
Thank you @chosak for the suggestions. |
This annual task involves downloading fixed-width files from HUD,
formatting them, combining them and producing a final file that can be
loaded into the owning-a-home API. Included here are a script to
automate that process and a management command to run the script.
Testing
It will fetch, process and save CSVs, but
git status
should show no changes, because the data files have already been updated for this year.If you run the command without a year, it will default to seeking next year's data files, which are not yet available. So you should see the failure message beginning with "Script failed to process all files," and no files should be saved.
@mthibos If stars align, we should be able to run the bare command next December and grab 2018 values.