-
Notifications
You must be signed in to change notification settings - Fork 4
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
Simplify Socrata API script and allow multiple assets to be updated #745
base: master
Are you sure you want to change the base?
Conversation
@@ -36,6 +36,8 @@ def parse_years(years): | |||
Make sure the years environmental variable is formatted correctly. | |||
""" | |||
|
|||
if years == "": |
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.
Just want to add a bit more error handling. Probably won't ever be needed.
session.get( | ||
( | ||
"https://datacatalog.cookcountyil.gov/resource/" | ||
+ asset_id | ||
+ ".json?$limit=1" | ||
), | ||
headers={"X-App-Token": app_token}, | ||
).raise_for_status() | ||
|
||
session.get(url=url, headers={"X-App-Token": app_token}).raise_for_status() |
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.
We were checking for a bad URL status twice.
overwrite = False | ||
print(response.content) | ||
|
||
# Return the updated count so that if this function is called in a loop | ||
# the updated count persists. | ||
return count | ||
overwrite = False |
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.
Ensuring overwrite can never be true
more than once per asset.
socrata/socrata_upload.py
Outdated
conditional if `years` is non-empty. Many of the CCAO's open data assets are | ||
Build a dictionary of Athena compatible SQL queries and their associated years. Many of the CCAO's open data assets are |
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 is the meat of what's changing here.
dbt/models/open_data/exposures.yml
Outdated
@@ -199,7 +199,7 @@ exposures: | |||
name: Data Department | |||
meta: | |||
test_row_count: true | |||
asset_id: vgzx-68gb | |||
asset_id: 3sp4-s4qg |
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.
Needs to be reverted before merging.
Comma-separated Socrata assets to update. Options are: | ||
Appeals | | ||
Assessed Values | | ||
Parcel Addresses | | ||
Parcel Proximity | | ||
Parcel Sales | | ||
Parcel Status | | ||
Permits | | ||
Property Tax-Exempt Parcels | | ||
Parcel Universe (Historic) | | ||
Parcel Universe (Current Year) | | ||
Residential Condominium Unit Characteristics | | ||
Single and Multi-Family Improvement Characteristics |
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 is gross, but I can't think of a better way to inform users of their choices since multiple choice isn't an input type and the github actions drop down menu doesn't seem to respect yaml line break formatting.
@@ -88,6 +101,9 @@ def get_asset_info(socrata_asset): | |||
Simple helper function to retrieve asset-specific information from dbt. | |||
""" | |||
|
|||
if not os.path.isdir("./dbt"): |
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.
Only helpful locally, unnecessary for github deployment.
# Comma separated list of years | ||
type: string | ||
description: Years to update or overwrite (comma-separated) | ||
default: 'all' |
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.
Removed the default and explained user's choices.
This started as trying to allow this script to accept multiple assets, but working with it was a chore and it was clear it could be simplified and improved.
This PR really just shifts a lot of the looping and year handling to the query building and upload functions and removes a lot of
overwrite
parameter handling involving acount
variable by only allowingoverwrite
to be true the first time it's handled.