Skip to content

Commit

Permalink
Handle a blank download a little differently
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Sep 1, 2024
1 parent f7562b1 commit 989afae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/continuous-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:

- id: download-data
name: Download data
run: python cpi/download.py
run: python -c 'import cpi'

- id: tests
name: Run tests
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
- id: download-data
name: Download data
run: $CONDA/bin/conda run -n cpi python cpi/download.py
run: $CONDA/bin/conda run -n cpi python -c 'import cpi'

- id: tests
name: Run tests
Expand Down
9 changes: 9 additions & 0 deletions cpi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import numbers
import warnings
from datetime import date, datetime
from pathlib import Path

from . import models
from .defaults import DEFAULT_SERIES_ID, DEFAULTS_SERIES_ATTRS
Expand All @@ -15,6 +16,14 @@
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

# Check if the cpi.db database exists, if not, download it.
this_dir = Path(__file__).parent.absolute()
db_path = this_dir / "cpi.db"
if not db_path.exists():
logger.info("CPI database not found. Downloading...")
Downloader().update()

# Create a list of all available series, will be lazy loaded as we go
series = models.SeriesList()

# Set the default series to the CPI-U
Expand Down
3 changes: 2 additions & 1 deletion cpi/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
from pathlib import Path

import pandas as pd
import parsers
import requests

from cpi import parsers

logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())

Expand Down

0 comments on commit 989afae

Please sign in to comment.