You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@fgregg I made some progress using a metaclass to programmatically pull in each client's supported years, default year, and enpoint urls from the discovery tool:
importrequestsfromfunctoolsimportlru_cache@lru_cachedeffetch_metadata():
# Fetches bulk metadata from the US Census' Discovery Tool APIr=requests.get("https://api.census.gov/data.json")
returnr.json()
classClientMeta(type):
def__init__(cls, name, bases, dct):
metadata=fetch_metadata()
ifnothasattr(cls, "dataset"):
returnsuper().__init__(name, bases, dct)
# Initialize years attributesetattr(cls, "years", set())
# e.g. ACS5Client.dataset is "acs/acs5" which corresponds to a metadata# object with a dataset attribute of ["acs", "acs5"]dataset=cls.dataset.split("/")
forminmetadata["dataset"]:
if"c_vintage"notinm:
continueifm["c_dataset"] ==dataset:
cls.years.add(m["c_vintage"])
# Set API URL attributessetattr(cls, "definitions_url", m["c_variablesLink"])
setattr(cls, "groups_url", m["c_groupsLink"])
setattr(cls, "default_year", max(cls.years))
returnsuper().__init__(name, bases, dct)
https://www.census.gov/data/developers/updates/new-discovery-tool.html
The text was updated successfully, but these errors were encountered: