Skip to content

Commit

Permalink
raise exception on invalid authentication (200 response from SGW)
Browse files Browse the repository at this point in the history
properly initialize favorites cache (dict instead of list #24)
  • Loading branch information
scottmconway committed Feb 15, 2024
1 parent dcf5c07 commit 181af71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
7 changes: 2 additions & 5 deletions bid_sniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,9 @@ def __init__(self, config: Dict, dry_run: bool = False) -> None:
if self.bid_time_delta == datetime.timedelta(0):
self.logger.warning("Invalid time delta string '{time_delta_str}'")

# TODO I hate this
self.favorites_cache = {
"last_updated": datetime.datetime.fromisoformat("1970-01-01").astimezone(
ZoneInfo("Etc/UTC")
),
"favorites": list(),
"last_updated": datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc),
"favorites": dict(),
}

self.scheduled_tasks = (
Expand Down
11 changes: 8 additions & 3 deletions shopgoodwill.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Shopgoodwill:
"block_size": 16,
}
FAVORITES_MAX_NOTE_LENGTH = 256
INVALID_AUTH_MESSAGE = "The username or password are incorrect"

def shopgoodwill_err_hook(self, res: Response, *args, **kwargs) -> None:
res.raise_for_status()
Expand Down Expand Up @@ -205,12 +206,16 @@ def login(self, username: str, password: str):

self.shopgoodwill_session.hooks["response"] = self.shopgoodwill_err_hook

res = self.shopgoodwill_session.post(
res_json = self.shopgoodwill_session.post(
Shopgoodwill.API_ROOT + "/SignIn/Login", json=login_params
)
).json()

if res_json["message"] == Shopgoodwill.INVALID_AUTH_MESSAGE:
raise Exception("Invalid credentials")

self.shopgoodwill_session.headers[
"Authorization"
] = f"Bearer {res.json()['accessToken']}"
] = f"Bearer {res_json['accessToken']}"
# TODO deal with refresh token

return True
Expand Down

0 comments on commit 181af71

Please sign in to comment.