Skip to content

Commit

Permalink
refactor: raise ValueError if EIA_TOKEN is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
csautter committed Oct 14, 2024
1 parent c03bf81 commit 7c755f9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions myeia/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
level=logging.INFO, format="%(asctime)s - %(message)s", datefmt="%d-%b-%y %H:%M:%S"
)

load_dotenv()

load_dotenv(verbose=True)

class API:
"""
Expand All @@ -30,7 +29,13 @@ def __init__(
self,
token: Optional[str] = None,
):
self.token = token if token else os.getenv("EIA_TOKEN")
if token:
self.token = token
elif os.getenv("EIA_TOKEN"):
self.token = os.getenv("EIA_TOKEN")
else:
raise ValueError('EIA_TOKEN is not set. Please set it in your .env file or environment variables.')

self.base_url = "https://api.eia.gov/v2/"
self.header = {"Accept": "*/*"}

Expand Down

0 comments on commit 7c755f9

Please sign in to comment.