Skip to content

Commit

Permalink
auth now updates rather than over-writes auth.json, closes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Aug 22, 2022
1 parent 9ef729a commit 3b57590
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pocket_to_sqlite/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import click
import json
import urllib.parse
import pathlib
import requests
import sqlite_utils
from . import utils
Expand Down Expand Up @@ -47,17 +48,21 @@ def auth(auth):
codes = dict(urllib.parse.parse_qsl(response2.text))

codes["consumer_key"] = CONSUMER_KEY
open(auth, "w").write(
json.dumps(
{
"pocket_consumer_key": CONSUMER_KEY,
"pocket_username": codes["username"],
"pocket_access_token": codes["access_token"],
},
indent=4,
)
+ "\n"

auth_data = {}
auth_path = pathlib.Path(auth)
if auth_path.exists():
auth_data = json.loads(auth_path.read_text())

auth_data.update(
{
"pocket_consumer_key": CONSUMER_KEY,
"pocket_username": codes["username"],
"pocket_access_token": codes["access_token"],
}
)

open(auth, "w").write(json.dumps(auth_data, indent=4) + "\n")
click.echo("Authentication tokens written to {}".format(auth))


Expand Down

0 comments on commit 3b57590

Please sign in to comment.