51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Print TELEGRAM_* assignments from known VPS env files (stdout only)."""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
WANTED = (
|
|
'TELEGRAM_BOT_TOKEN',
|
|
'TELEGRAM_GROUP_CHAT_ID',
|
|
'TELEGRAM_GROUP_THREAD_ID',
|
|
'TELEGRAM_CHAT_ID',
|
|
)
|
|
PATHS = (
|
|
Path('/opt/ghabilee-backend/.env'),
|
|
Path('/opt/ghabilee/backend/.env'),
|
|
Path('/opt/ghabilee-admin/.env'),
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
found: dict[str, str] = {}
|
|
for path in PATHS:
|
|
if not path.is_file() or path.stat().st_size == 0:
|
|
continue
|
|
for raw in path.read_text(encoding='utf-8', errors='replace').splitlines():
|
|
line = raw.strip()
|
|
if not line or line.startswith('#') or '=' not in line:
|
|
continue
|
|
key, value = line.split('=', 1)
|
|
key = key.strip()
|
|
if key not in WANTED or key in found:
|
|
continue
|
|
value = value.strip()
|
|
if len(value) >= 2 and value[0] == value[-1] and value[0] in "\"'":
|
|
value = value[1:-1]
|
|
# Inline comments in .env (e.g. THREAD_ID=8 # ops)
|
|
if ' #' in f' {value}':
|
|
value = value.split('#', 1)[0].rstrip()
|
|
value = value.replace('\n', '').replace('\r', '')
|
|
found[key] = value
|
|
if 'TELEGRAM_BOT_TOKEN' in found:
|
|
break
|
|
|
|
for key in WANTED:
|
|
if key in found and found[key]:
|
|
print(f'{key}={found[key]}')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|