cheia API se ia din .env

Loader pe stdlib (fara python-dotenv): mediul are prioritate, altfel .env de
langa script. .env e in .gitignore, .env.example e sablonul versionat.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KHLUSsKP99G6ebv2fFUKQV
This commit is contained in:
2026-09-17 21:50:45 +03:00
parent 2d012a969c
commit fd869ce20c
3 changed files with 32 additions and 8 deletions

View File

@@ -1,10 +1,25 @@
# Test TypeSafe System One - stdlib, fara dependinte.
# Rulare: set TYPESAFE_API_KEY=... apoi: python typesafe_test.py
import json, os, sys, urllib.request
# Rulare: pune cheia in .env apoi: python typesafe_test.py
import io, json, os, sys, urllib.request
KEY = os.environ.get("TYPESAFE_API_KEY")
if not KEY:
sys.exit("Lipseste TYPESAFE_API_KEY in mediu.")
def cheie():
"""Din mediu daca e setata, altfel din .env de langa script."""
k = os.environ.get("TYPESAFE_API_KEY")
if k:
return k
env = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".env")
if os.path.exists(env):
for linie in io.open(env, encoding="utf-8"):
linie = linie.strip()
if linie.startswith("TYPESAFE_API_KEY="):
return linie.split("=", 1)[1].strip().strip("'\"")
return None
KEY = cheie()
if not KEY or KEY == "pune_cheia_aici":
sys.exit("Lipseste cheia: pune-o in .env (TYPESAFE_API_KEY=...) sau in mediu.")
# state = ce vede modelul. Aici: o linie de factura de furnizor + candidatii scosi "din Oracle".
payload = {