From 37869f7c5c3f8c62c91b71cd11a7ad6362405325 Mon Sep 17 00:00:00 2001 From: Pierre Porcher Date: Tue, 6 Jan 2026 14:03:44 +0100 Subject: [PATCH] fix login when xdg config home does not exist --- nbs/00_cli.ipynb | 6 +++--- plash_cli/cli.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nbs/00_cli.ipynb b/nbs/00_cli.ipynb index a15a159..a82bf0d 100644 --- a/nbs/00_cli.ipynb +++ b/nbs/00_cli.ipynb @@ -39,7 +39,7 @@ "#| export\n", "from fastcore.all import *\n", "from fastcore.xdg import *\n", - "import secrets, webbrowser, json, httpx, io, tarfile, random, string\n", + "import secrets, webbrowser, httpx, io, tarfile, random, string\n", "from pathlib import Path\n", "from uuid import uuid4\n", "from time import time, sleep\n", @@ -222,7 +222,7 @@ " if not PLASH_CONFIG_HOME.exists(): return print(\"No config found.\")\n", " return print(PLASH_CONFIG_HOME.read_json().get(\"session_\", \"\"), end='')\n", " if token:\n", - " PLASH_CONFIG_HOME.write_text(json.dumps({\"session_\": token.strip()}))\n", + " PLASH_CONFIG_HOME.write_json({\"session_\": token.strip()})\n", " return f\"Token saved to {PLASH_CONFIG_HOME}\"\n", " paircode = secrets.token_urlsafe(16)\n", " login_url = httpx.get(_endpoint(rt=f\"/cli_login?paircode={paircode}\")).text\n", @@ -231,7 +231,7 @@ " \n", " cookies = _poll_cookies(paircode)\n", " if cookies:\n", - " PLASH_CONFIG_HOME.write_text(json.dumps(cookies))\n", + " PLASH_CONFIG_HOME.write_json(cookies)\n", " print(f\"Authentication successful! Config saved to {PLASH_CONFIG_HOME}\")\n", " else: print(\"Authentication timed out.\")" ] diff --git a/plash_cli/cli.py b/plash_cli/cli.py index 4dd1be4..ae5f718 100644 --- a/plash_cli/cli.py +++ b/plash_cli/cli.py @@ -9,7 +9,7 @@ # %% ../nbs/00_cli.ipynb 3 from fastcore.all import * from fastcore.xdg import * -import secrets, webbrowser, json, httpx, io, tarfile, random, string +import secrets, webbrowser, httpx, io, tarfile, random, string from pathlib import Path from uuid import uuid4 from time import time, sleep @@ -92,7 +92,7 @@ def login( if not PLASH_CONFIG_HOME.exists(): return print("No config found.") return print(PLASH_CONFIG_HOME.read_json().get("session_", ""), end='') if token: - PLASH_CONFIG_HOME.write_text(json.dumps({"session_": token.strip()})) + PLASH_CONFIG_HOME.write_json({"session_": token.strip()}) return f"Token saved to {PLASH_CONFIG_HOME}" paircode = secrets.token_urlsafe(16) login_url = httpx.get(_endpoint(rt=f"/cli_login?paircode={paircode}")).text @@ -101,7 +101,7 @@ def login( cookies = _poll_cookies(paircode) if cookies: - PLASH_CONFIG_HOME.write_text(json.dumps(cookies)) + PLASH_CONFIG_HOME.write_json(cookies) print(f"Authentication successful! Config saved to {PLASH_CONFIG_HOME}") else: print("Authentication timed out.")