admin/scripts/extract-telegram-env.py
alisaza ac8bb3bae1 fix: send admin deploy Telegram alerts from Actions runner [skip ci]
Iran VPS cannot reach api.telegram.org, and sourcing backend .env broke
on BOOKING_EXPIRY_CRON globs. Extract TELEGRAM_* safely over SSH and
notify from the foreign act_runner instead.
2026-09-13 18:31:13 +03:30

48 lines
1.3 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]
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()