uses dotenv to store api key and other important variables

if a value is not found in .env it will be prompted, but not checked
next step is user docs
This commit is contained in:
2026-05-13 12:31:26 +02:00
parent 686f869d10
commit ee96100a73
2 changed files with 18 additions and 11 deletions

View File

@@ -1,4 +1,5 @@
import os, requests
from dotenv import load_dotenv
from getpass import getpass
import elabapi_python as elabapi
@@ -20,10 +21,13 @@ class APIHandler:
"""
# TO-DO: remove static url.
def __init__(
self, api_key="", ELABFTW_API_URL="https://elabftw.fisica.unina.it/api/v2"
):
def __init__(self, api_key="", ELABFTW_API_URL=None):
"""Init method, api_key suggested but not required (empty by default)."""
if not ELABFTW_API_URL:
load_dotenv()
ELABFTW_API_URL = os.getenv("ELABFTW_API_URL") or input(
"Enter a valid eLabFTW API URL (ends with '/api/v2)': "
)
self.api_key = api_key
self.auth = {"Authorization": api_key}
self.content = {"Content-Type": "application/json"}