dbc_path = f"{self.get_dir(year)}/{filename}"
resource = next(self.get_resources("ferc1", year=year))
z = zipfile.ZipFile(resource["path"])
try:
f = z.open(dbc_path)
except KeyError:
raise KeyError(f"{dbc_path} is not available in {year} archive.")
return f
After Change
def get_file(self, year: int, filename: str):
if year not in self._cache:
self._cache[year] = self.datastore.get_zipfile_resource("ferc1", year=year)
archive = self._cache[year]
try:
return archive.open(f"{self.get_dir(year)}/{filename}")
except KeyError:
raise KeyError(f"{filename} not availabe for year {year} in ferc1.")