-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathconfig.py
More file actions
50 lines (38 loc) · 1.59 KB
/
config.py
File metadata and controls
50 lines (38 loc) · 1.59 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
import json
from pathlib import Path
CONFIG_PATH = Path(__file__).resolve().parent / "config.json"
DEFAULTS = {
"api_url": "https://mof.sora.org",
"substrate_url": "wss://mof2.sora.org",
"network": "mainnet",
"default_dex_id": 0,
"timeout": 30,
"log_level": "INFO",
}
def load_config() -> dict:
cfg = dict(DEFAULTS)
if CONFIG_PATH.exists():
try:
with CONFIG_PATH.open("r", encoding="utf-8") as fh:
data = json.load(fh)
cfg.update(data)
except (json.JSONDecodeError, OSError):
pass
return cfg
def save_config(cfg: dict) -> None:
with CONFIG_PATH.open("w", encoding="utf-8") as fh:
json.dump(cfg, fh, indent=2)
def interactive_setup() -> None:
from rich.console import Console
from rich.prompt import Prompt
console = Console()
cfg = load_config()
console.print("[bold #e6007a]SORA v2 API Configuration[/bold #e6007a]\n")
console.print("Press Enter to keep current value.\n")
cfg["api_url"] = Prompt.ask("SORA API base URL", default=cfg["api_url"])
cfg["substrate_url"] = Prompt.ask("Substrate WebSocket URL", default=cfg["substrate_url"])
cfg["network"] = Prompt.ask("Network", choices=["mainnet", "testnet"], default=cfg["network"])
cfg["default_dex_id"] = int(Prompt.ask("Default DEX ID", default=str(cfg["default_dex_id"])))
cfg["timeout"] = int(Prompt.ask("Request timeout (seconds)", default=str(cfg["timeout"])))
save_config(cfg)
console.print("\n[bold green]Configuration saved.[/bold green]")