-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_config.py
More file actions
61 lines (44 loc) · 1.71 KB
/
Copy path_config.py
File metadata and controls
61 lines (44 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Shared config loader: reads wallets and options from environment / .env."""
from __future__ import annotations
import os
import sys
from datetime import datetime
from pathlib import Path
def _load_dotenv() -> None:
"""Load KEY=VALUE pairs from .env (script dir, then cwd) into os.environ."""
seen = set()
for base in (Path(__file__).parent, Path.cwd()):
if base in seen:
continue
seen.add(base)
f = base / ".env"
if not f.exists():
continue
for line in f.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
k, _, v = line.partition("=")
k = k.strip()
v = v.strip().strip("'").strip('"')
if k and k not in os.environ:
os.environ[k] = v
def _require(name: str) -> str:
v = os.environ.get(name, "").strip()
if not v:
print(f"ERROR: {name} environment variable not set.", file=sys.stderr)
print(f" Copy .env.example to .env and fill in your values, or export the variable.", file=sys.stderr)
sys.exit(1)
return v
_load_dotenv()
def get_tezos_wallets() -> list[str]:
return [w.strip() for w in _require("TEZOS_WALLETS").split(",") if w.strip()]
def get_evm_wallet() -> str:
return _require("EVM_WALLET").lower()
def get_start_date_iso() -> str:
return os.environ.get("START_DATE", "2021-01-01") + "T00:00:00Z"
def get_start_ts() -> int:
s = os.environ.get("START_DATE", "2021-01-01")
return int(datetime.fromisoformat(f"{s}T00:00:00+00:00").timestamp())
def get_etherscan_key() -> str:
return _require("ETHERSCAN_API_KEY")