Skip to content
This repository has been archived by the owner on Aug 10, 2024. It is now read-only.

Commit

Permalink
api key logic
Browse files Browse the repository at this point in the history
  • Loading branch information
aliig committed Nov 28, 2023
1 parent 8919707 commit 5be46b8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

load_dotenv() # Load environment variables from .env file

API_KEY = os.getenv("CURSEFORGE_API_KEY")


@dataclass
class Mod:
Expand All @@ -25,6 +23,15 @@ class Mod:
latest_dt: datetime | None


def _get_api_key() -> str:
key = os.getenv("CURSEFORGE_API_KEY")
if key:
logger.debug("CURSEFORGE_API_KEY found in environment variables")
else:
logger.warning("CURSEFORGE_API_KEY not found in environment variables")
return key


@cache
def _local_mod_file() -> dict:
file_path = os.path.join(
Expand Down Expand Up @@ -72,7 +79,7 @@ def _get_latest_mods_timestamps(mod_ids: list[int]) -> dict[int, tuple[str, date
headers = {
"Content-Type": "application/json",
"Accept": "application/json",
"x-api-key": API_KEY,
"x-api-key": _get_api_key(),
}
payload = {"modIds": mod_ids, "filterPcOnly": True}

Expand Down

0 comments on commit 5be46b8

Please sign in to comment.