Skip to content

Commit b7bb7a4

Browse files
authored
Merge pull request #42 from wimglenn/cookies-os
v0.9.4
2 parents 388ff88 + 652bb64 commit b7bb7a4

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

aocd/cookies.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,22 +85,38 @@ def scrape_session_tokens():
8585
try:
8686
import browser_cookie3 as bc3 # soft dependency
8787
except ImportError:
88-
sys.exit("To use this feature you must install browser-cookie3")
88+
sys.exit("To use this feature you must pip install browser-cookie3")
8989

9090
log.info("checking browser cookies storage for auth tokens, this might pop up an auth dialog!")
9191
log.info("checking chrome cookie jar...")
92-
cookie_jar_chrome = bc3.chrome(domain_name=".adventofcode.com")
93-
chrome = [c for c in cookie_jar_chrome if c.name == "session"]
94-
log.info("%d candidates from chrome", len(chrome))
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))
95101

96102
log.info("checking firefox cookie jar...")
97-
cookie_jar_firefox = bc3.firefox(domain_name=".adventofcode.com")
98-
firefox = [c for c in cookie_jar_firefox if c.name == "session"]
99-
log.info("%d candidates from firefox", len(firefox))
103+
try:
104+
firefox = bc3.firefox(domain_name=".adventofcode.com")
105+
except Exception as err:
106+
log.debug("Couldn't scrape firefox - %s: %s", type(err), err)
107+
firefox = []
108+
else:
109+
firefox = [c for c in firefox if c.name == "session"]
110+
log.info("%d candidates from firefox", len(firefox))
111+
112+
# order preserving de-dupe
113+
tokens = list({}.fromkeys([c.value for c in chrome + firefox]))
114+
removed = len(chrome + firefox) - len(tokens)
115+
if removed:
116+
log.info("Removed %d duplicate%s", removed, "s"[:removed-1])
100117

101118
working = {} # map of {token: auth source}
102-
for cookie in chrome + firefox:
103-
token = cookie.value
119+
for token in tokens:
104120
owner = get_owner(token)
105121
if owner is not None:
106122
working[token] = owner

aocd/get.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,22 @@ def get_day_and_year():
106106
"/IPython/" in name, # IPython adds a tonne of stack frames
107107
name.startswith("<"), # crap like <decorator-gen-57>
108108
name.endswith("ython3"), # ipython3 alias
109+
basename.startswith("pydev_ipython_console"), # PyCharm Python Console
109110
]
110111
if not any(reasons_to_skip_frame):
112+
log.debug("stack crawl found %s", name)
111113
abspath = os.path.abspath(name)
112114
break
113115
log.debug("skipping frame %s", name)
114116
else:
115117
import __main__
116-
117-
try:
118-
__main__.__file__
119-
except AttributeError:
118+
if getattr(__main__, "__file__", "<input>") == "<input>":
120119
log.debug("running within REPL")
121120
day = current_day()
122121
year = most_recent_year()
123122
return day, year
124-
else:
125-
log.debug("non-interactive")
126-
raise AocdError("Failed introspection of filename")
123+
log.debug("non-interactive")
124+
raise AocdError("Failed introspection of filename")
127125
years = {int(year) for year in re.findall(pattern_year, abspath)}
128126
if len(years) > 1:
129127
raise AocdError("Failed introspection of year")

aocd/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.9.3"
1+
__version__ = "0.9.4"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="advent-of-code-data",
6-
version="0.9.3",
6+
version="0.9.4",
77
description="Get your puzzle data with a single import",
88
long_description=open("README.rst").read(),
99
long_description_content_type="text/x-rst",

0 commit comments

Comments
 (0)