aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-06-29 02:29:39 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2023-06-29 22:15:55 +0200
commit093d0c51cd115c028485f5906ff979bc7332ebcb (patch)
treed833a254218a23014dadfd6d87bd842f0020e979
parent4b6042a33bc276446b8ce937ef137947e292a048 (diff)
downloadwee-slack-093d0c51cd115c028485f5906ff979bc7332ebcb.tar.gz
Refactor get_cookies
-rwxr-xr-xextract_token_from_browser.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/extract_token_from_browser.py b/extract_token_from_browser.py
index 3cc110a..6ed7e22 100755
--- a/extract_token_from_browser.py
+++ b/extract_token_from_browser.py
@@ -38,18 +38,21 @@ def sqlite3_connect(path: StrPath):
con.close()
-def get_cookies(cookies_path: StrPath, cookie_d_query: str, cookie_ds_query: str):
- cookie_d_value = None
- try:
- with sqlite3_connect(cookies_path) as con:
- cookie_d_value = con.execute(cookie_d_query).fetchone()[0]
- cookie_ds_value = con.execute(cookie_ds_query).fetchone()[0]
- return cookie_d_value, cookie_ds_value
- except TypeError:
- if not cookie_d_value:
- print("Couldn't find the 'd' cookie value", file=sys.stderr)
+def get_cookies(
+ cookies_path: StrPath, cookie_d_query: str, cookie_ds_query: str
+) -> tuple[str, str | None]:
+ with sqlite3_connect(cookies_path) as con:
+ cookie_d_value = con.execute(cookie_d_query).fetchone()
+ cookie_ds_value = con.execute(cookie_ds_query).fetchone()
+ if cookie_d_value and cookie_ds_value:
+ return cookie_d_value[0], cookie_ds_value[0]
+ elif cookie_d_value:
+ return cookie_d_value[0], None
+ else:
+ print(
+ f"Couldn't find the 'd' cookie value in {cookies_path}", file=sys.stderr
+ )
sys.exit(1)
- return cookie_d_value, None
parser = argparse.ArgumentParser(