Skip to content

Commit 2953884

Browse files
authored
Merge pull request #5 from openstates/fix-to-initdb
Set default value for init_duckdb()
2 parents fd8945d + 6a718a4 commit 2953884

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

sqlmesh_tasks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ def sqlmesh_plan(entities: list[str], jurisdiction: str) -> list:
2727
initialize_entities = [f"staged.{entity}" for entity in initialize_entities]
2828
reports = []
2929

30+
if not initialize_entities:
31+
logger.info(
32+
"No entities were initialized for auditing. Please verify that the data directory exists and contains valid JSON files."
33+
)
34+
return reports
3035
for entity in initialize_entities:
3136
command = [
3237
"poetry",

utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def check_for_json_files(file_path: str) -> bool:
1818
return len(matching_files) > 0
1919

2020

21-
def download_files_from_gcs(jur_abbreviation: str, file_path: str) -> None:
21+
def download_files_from_gcs(file_path: str) -> None:
2222
"""Download from GCS to local directory"""
2323
try:
2424
cloud_storage_client = storage.Client(project=GCP_PROJECT)
@@ -47,13 +47,12 @@ def download_files_from_gcs(jur_abbreviation: str, file_path: str) -> None:
4747
logger.warning(
4848
f"An error occurred during the attempt to download files from Google Cloud Storage: {e}"
4949
)
50-
raise
5150

5251

5352
def init_duckdb(
5453
jurisdiction: str,
5554
entities: list[str],
56-
last_scrape_time: str,
55+
last_scrape_end_time: str = None,
5756
) -> list[str]:
5857
"""Initialize Duckdb and load data, return list of tables created for usage downstream."""
5958

@@ -62,9 +61,9 @@ def init_duckdb(
6261
os.remove(db_path)
6362

6463
sub_directory = "*"
65-
if jurisdiction and last_scrape_time:
64+
if jurisdiction and last_scrape_end_time:
6665
sub_directory = jurisdiction.replace("ocd-jurisdiction/", "")
67-
sub_directory = f"{sub_directory}/{last_scrape_time}"
66+
sub_directory = f"{sub_directory}/{last_scrape_end_time}"
6867
# Create DuckDB and load
6968
logger.info("Creating DuckDB schema and loading data...")
7069
con = duckdb.connect(db_path)
@@ -79,7 +78,7 @@ def init_duckdb(
7978
logger.info(
8079
"No file found in local directory, attempting to download from GCS, requires credentials in ENV."
8180
)
82-
download_files_from_gcs(jurisdiction, sub_directory)
81+
download_files_from_gcs(sub_directory)
8382

8483
# Load data into duckdb table
8584
for entity in entities:

0 commit comments

Comments
 (0)