Skip to content

Commit 3778c39

Browse files
committed
chrome linux fix
closes #41
1 parent c441b0d commit 3778c39

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

aocd/cookies.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import glob
23
import json
34
import logging
45
import os
@@ -64,7 +65,9 @@ def scrape_session_tokens():
6465
tokens["AOC_SESSION"] = os.environ["AOC_SESSION"]
6566
if os.path.isfile(aocd_token_file):
6667
with open(aocd_token_file) as f:
67-
tokens[aocd_token_file] = f.read().split()[0]
68+
txt = f.read().strip()
69+
if txt:
70+
tokens[aocd_token_file] = txt.split()[0]
6871
if os.path.isfile(aocd_tokens_file):
6972
with open(aocd_tokens_file) as f:
7073
tokens.update(json.load(f))
@@ -89,15 +92,17 @@ def scrape_session_tokens():
8992

9093
log.info("checking browser cookies storage for auth tokens, this might pop up an auth dialog!")
9194
log.info("checking chrome cookie jar...")
92-
try:
93-
chrome = bc3.chrome(domain_name=".adventofcode.com")
94-
# TODO: check non-default profile for chrome/linux
95-
except Exception as err:
96-
log.debug("Couldn't scrape chrome - %s: %s", type(err), err)
97-
chrome = []
98-
else:
99-
chrome = [c for c in chrome if c.name == "session"]
100-
log.info("%d candidates from chrome", len(chrome))
95+
cookie_files = glob.glob(os.path.expanduser("~/.config/google-chrome/*/Cookies")) + [None]
96+
chrome_cookies = []
97+
for cookie_file in cookie_files:
98+
try:
99+
chrome = bc3.chrome(cookie_file=cookie_file, domain_name=".adventofcode.com")
100+
except Exception as err:
101+
log.debug("Couldn't scrape chrome - %s: %s", type(err), err)
102+
else:
103+
chrome_cookies += [c for c in chrome if c.name == "session"]
104+
log.info("%d candidates from chrome", len(chrome_cookies))
105+
chrome = chrome_cookies
101106

102107
log.info("checking firefox cookie jar...")
103108
try:

0 commit comments

Comments
 (0)