Skip to content

Commit 21797c1

Browse files
authored
Merge pull request #75 from pporcher/make-xdg-config-home
Fix login when xdg config home directory does not exist
2 parents 68c1d50 + 37869f7 commit 21797c1

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

nbs/00_cli.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"#| export\n",
4040
"from fastcore.all import *\n",
4141
"from fastcore.xdg import *\n",
42-
"import secrets, webbrowser, json, httpx, io, tarfile, random, string\n",
42+
"import secrets, webbrowser, httpx, io, tarfile, random, string\n",
4343
"from pathlib import Path\n",
4444
"from uuid import uuid4\n",
4545
"from time import time, sleep\n",
@@ -222,7 +222,7 @@
222222
" if not PLASH_CONFIG_HOME.exists(): return print(\"No config found.\")\n",
223223
" return print(PLASH_CONFIG_HOME.read_json().get(\"session_\", \"\"), end='')\n",
224224
" if token:\n",
225-
" PLASH_CONFIG_HOME.write_text(json.dumps({\"session_\": token.strip()}))\n",
225+
" PLASH_CONFIG_HOME.write_json({\"session_\": token.strip()})\n",
226226
" return f\"Token saved to {PLASH_CONFIG_HOME}\"\n",
227227
" paircode = secrets.token_urlsafe(16)\n",
228228
" login_url = httpx.get(_endpoint(rt=f\"/cli_login?paircode={paircode}\")).text\n",
@@ -231,7 +231,7 @@
231231
" \n",
232232
" cookies = _poll_cookies(paircode)\n",
233233
" if cookies:\n",
234-
" PLASH_CONFIG_HOME.write_text(json.dumps(cookies))\n",
234+
" PLASH_CONFIG_HOME.write_json(cookies)\n",
235235
" print(f\"Authentication successful! Config saved to {PLASH_CONFIG_HOME}\")\n",
236236
" else: print(\"Authentication timed out.\")"
237237
]

plash_cli/cli.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# %% ../nbs/00_cli.ipynb 3
1010
from fastcore.all import *
1111
from fastcore.xdg import *
12-
import secrets, webbrowser, json, httpx, io, tarfile, random, string
12+
import secrets, webbrowser, httpx, io, tarfile, random, string
1313
from pathlib import Path
1414
from uuid import uuid4
1515
from time import time, sleep
@@ -92,7 +92,7 @@ def login(
9292
if not PLASH_CONFIG_HOME.exists(): return print("No config found.")
9393
return print(PLASH_CONFIG_HOME.read_json().get("session_", ""), end='')
9494
if token:
95-
PLASH_CONFIG_HOME.write_text(json.dumps({"session_": token.strip()}))
95+
PLASH_CONFIG_HOME.write_json({"session_": token.strip()})
9696
return f"Token saved to {PLASH_CONFIG_HOME}"
9797
paircode = secrets.token_urlsafe(16)
9898
login_url = httpx.get(_endpoint(rt=f"/cli_login?paircode={paircode}")).text
@@ -101,7 +101,7 @@ def login(
101101

102102
cookies = _poll_cookies(paircode)
103103
if cookies:
104-
PLASH_CONFIG_HOME.write_text(json.dumps(cookies))
104+
PLASH_CONFIG_HOME.write_json(cookies)
105105
print(f"Authentication successful! Config saved to {PLASH_CONFIG_HOME}")
106106
else: print("Authentication timed out.")
107107

0 commit comments

Comments
 (0)