1
1
import argparse
2
+ import glob
2
3
import json
3
4
import logging
4
5
import os
@@ -64,7 +65,9 @@ def scrape_session_tokens():
64
65
tokens ["AOC_SESSION" ] = os .environ ["AOC_SESSION" ]
65
66
if os .path .isfile (aocd_token_file ):
66
67
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 ]
68
71
if os .path .isfile (aocd_tokens_file ):
69
72
with open (aocd_tokens_file ) as f :
70
73
tokens .update (json .load (f ))
@@ -89,15 +92,17 @@ def scrape_session_tokens():
89
92
90
93
log .info ("checking browser cookies storage for auth tokens, this might pop up an auth dialog!" )
91
94
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
101
106
102
107
log .info ("checking firefox cookie jar..." )
103
108
try :
0 commit comments