from pathlib import Path from google_auth_oauthlib.flow import InstalledAppFlow from app.config import get_settings from app.google.auth import GOOGLE_SCOPES def main() -> None: settings = get_settings() workspace_root = Path(__file__).resolve().parents[1] client_path = (workspace_root / settings.google_client_secrets_file).resolve() token_path = (workspace_root / settings.google_token_file).resolve() token_path.parent.mkdir(parents=True, exist_ok=True) if not client_path.exists(): raise SystemExit( f"Missing Google OAuth client file: {client_path}\n" "Create a Google OAuth Desktop App and place its JSON there first." ) flow = InstalledAppFlow.from_client_secrets_file(str(client_path), GOOGLE_SCOPES) creds = flow.run_local_server(port=0, open_browser=True) token_path.write_text(creds.to_json(), encoding="utf-8") print(f"Google token saved to {token_path}") if __name__ == "__main__": main()