Skip to content

Commit

Permalink
Patch 1.2.0: Availability Table Parsing
Browse files Browse the repository at this point in the history
Turns out that when searching past the end of the campground's
'season' the calendar table does not update the availability table
properly becaus there is no data to display for that time range.
This commit addresses that possibility and fixes a few logging
message quirks.
  • Loading branch information
rmjacobson committed Sep 12, 2022
1 parent 300fb57 commit 9e21cfa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def send_alerts(available_campgrounds: CampgroundList) -> None:
Builds and sends 2 emails:
- one for an email alert sent to a convetional email address
- one for a text alert sent via carrier email/text gateway
:param available_campgrounds: list of newly available sites to send notifications for
:returns: True if both email and text notifications succeed, False otherwise.
"""
Expand Down
20 changes: 17 additions & 3 deletions scrape_availability.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,26 @@ def all_dates_available(df: DataFrame, start_date: datetime,
# cycle through date columns to check if there's at least `req_available_sites` for each day
tmp = 100
at_least_one_available = True
if not set(abbr_dates).issubset(set(df.columns)):
key_error_str = (f"Dates requested {abbr_dates} don't appear as columns in table; "
"either search has failed or requested dates are not in season.")
raise KeyError(key_error_str)
for col in df[abbr_dates].columns:
num_available_sites = df[col].value_counts()["A"]
num_available_sites = 0
try:
num_available_sites = df[col].value_counts()["A"]
except KeyError: # there are no "A" fields -> none available
short_circuit_log_msg = (f"Found column (aka date) with no 'A' cells, meaning no "
f"sites available ({req_available_sites} required); "
"short-circuit this search of table")
logger.debug(short_circuit_log_msg)
return False
at_least_one_available = num_available_sites >= req_available_sites
if not at_least_one_available:
logger.debug(("Found column (aka date) with only %d sites available (%d required); ",
"stopping search of table"), num_available_sites, req_available_sites)
short_circuit_log_msg = (f"Found column (aka date) with only {num_available_sites} "
f"sites available ({req_available_sites} required); "
"short-circuit this search of table")
logger.debug(short_circuit_log_msg)
return False
if num_available_sites < tmp:
tmp = num_available_sites
Expand Down
5 changes: 3 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ def exit_gracefully(signal_received, frame, close_this_driver: WebDriver=None):
:param driver: Selenium WebDriver to close before exiting
:returns: N/A
"""
logger.info(("Received CTRL-C/SIGNINT or daemon completed;",
"exiting gracefully/closing WebDriver if initialized."))
exit_msg = ("Received CTRL-C/SIGNINT or daemon completed;",
"exiting gracefully/closing WebDriver if initialized.")
logger.info(exit_msg)
if close_this_driver is not None:
# use quit instead of close to avoid tons of leftover chrome processes
# https://stackoverflow.com/questions/15067107/difference-between-webdriver-dispose-close-and-quit
Expand Down

0 comments on commit 9e21cfa

Please sign in to comment.