-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The recreation.gov site rewrite was a little more complicated than expected, these changers took a little longer than expected, and some code was touched that's not directly relevant to make things simpler. Overview of changes: - campground.py edited to remove the /availability path from the url field -- it's no longer needed as recreation.gov now displays the availability table on the main page - utils.py -- some functions like the graceful error handling and logging setup can be moved into a utils file so they can be used in modules as well as in the main daemon -- good for dev - daemon.py -- edit to use the utils file for logging/etc. - scrape_availability.py - improved how we enter/validate the start/end dates - improved detecting the results table-loading element - enabled closing recreation.gov tutorial window if it exists - fixed starting up chromium on raspbian (currently the only thing we support)
- Loading branch information
1 parent
60f1dbe
commit 5d08378
Showing
4 changed files
with
167 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
utils.py | ||
fill this out later | ||
""" | ||
|
||
import sys | ||
import logging | ||
from logging.handlers import TimedRotatingFileHandler | ||
from selenium.webdriver.chrome.webdriver import WebDriver | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def exit_gracefully(signal_received, frame, close_this_driver: WebDriver=None): | ||
""" | ||
Handler for SIGINT that will close webdriver carefully if necessary. | ||
Ref: https://www.devdungeon.com/content/python-catch-sigint-ctrl-c | ||
https://docs.python.org/3/library/signal.html | ||
:param signal_received: signal object received by handler | ||
:param frame: actually have no idea what this is and we never use it... | ||
: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.") | ||
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 | ||
close_this_driver.quit() | ||
logger.info("WebDriver Quit Successfully") | ||
sys.exit(0) | ||
|
||
def set_low_network_quality(driver: WebDriver) -> None: | ||
""" | ||
Set WebDriver to simulate low network quality -- 5ms additional latency, only 500kb | ||
throughput. Mostly used when testing the load actions of the availability table; sometimes | ||
there is a web element that shows up and spins for a while while the wait happens and it | ||
can be difficult to find the name for that without the appropriate delays set. | ||
Should never be used in production code, but left here for future testing needs. | ||
""" | ||
latency_delay_ms = 5 | ||
download_throughput_kb = 500 | ||
upload_throughput_kb = 500 | ||
driver.set_network_conditions( | ||
offline=False, | ||
latency=latency_delay_ms, | ||
download_throughput=download_throughput_kb, | ||
upload_throughput=upload_throughput_kb) | ||
|
||
def setup_logging() -> None: | ||
""" | ||
Set logging for whole project. This function is called from wherever the program | ||
is invoked. Could be from different places given development of different components | ||
separately. | ||
""" | ||
rotating_handler = TimedRotatingFileHandler("logs/recgov.log", when="d", interval=1, backupCount=5) | ||
rotating_handler.suffix = "%Y-%m-%d" | ||
logging.basicConfig( | ||
handlers=[rotating_handler], | ||
level=logging.INFO, | ||
format="[%(asctime)s] %(filename)s:%(lineno)d [%(name)s]%(levelname)s - %(message)s", | ||
) |