Bot to monitor for southbound permit spaces on the John Muir Trail
MIT License
This repository contains a Python script for monitoring Yosemite's permit availability report. Vacancies in this table indicate the availability of a southbound John Muir Trail permit, available for immediate reservation by filling out the online permit request form. This strategy enables securing a soutbound JMT permit after the lottery drawing for a given date.
Learn more about using hackjohn and its history of success in the blog post titled Introducing the hackjohn bot for southbound John Muir Trail permits and The Mercury News article titled Here’s how to get a coveted reservation to hike the John Muir Trail.
Follow these steps to run hackjohn:
config.py
with with the parameters of your permit search.hackjohn
appropriate environment (see Environment section) with:python hackjohn.py
The script will print some progress messages and at the end it will print a message containing available permit details. The same message will be sent via whichever notification services you set up. An example of the report is:
2021-08-20:
5 permits for Happy Isles->Little Yosemite Valley
2 permits for Lyell Canyon
2021-09-03:
1 permit for Happy Isles->Little Yosemite Valley
Report last updated 2021-03-20 10:34:32 AM PDT.
Permit request form: https://yosemite.org/yosemite-wilderness-permit-request-form/
Permit office phone: 209-372-0826
By default, hackjohn writes the output to the file hackjohn-output.txt
(as specified by the OUTPUT_PATH
variable in config.py
).
To avoid repeated notification, hackjohn skips sending notifications if its output matches the pre-existing output.
As of June 22, 2020, the trailhead report switched to a new website that moved the permit report behind a Recaptcha (the "I am not a robot" thing). This made it more difficult for bots to access the report.
hackjohn uses 2Captcha to solve the Recaptcha and get to the permit report.
You will need to create a 2Captcha account and upload some funds, then copy your 2Captcha API key into the CAPTCHA_API_KEY
variable in config.py
.
This costs money, but it is very cheap (a few dollars will get you 1000 Recaptchas). hackjohn reuses the same Recaptcha authorization as long as it is still valid, so it only calls the 2Captcha service when necessary (currently the authentication lasts about a day, but that is subject to change). Realistically, it will cost you at most a couple dollars to run hackjohn multiple times per day for an entire year.
Note: There are many alternatives to 2Captcha and they all work pretty much the same way. I didn't have any particular reason for choosing 2Captcha. Feel free to use a different Captcha solving service, but you will need to make modifications to the code.
hackjohn supports the following services to provide notifications:
The Telegram messaging app. Refer to the webhook2telegram repo for more details.
config.py
, set ENABLE_TELEGRAM
to True and set TELEGRAM_TOKEN
to the token you received in the previous step.If This Then That (IFTTT). (Thanks Markus Neuhoff for contributing this feature!)
IFTTT_EVENT_NAME
variable in config.py
.IFTTT_KEY
variable and set ENABLE_IFTTT
to True in config.py
.SMS text messages with Twilio.
TWILIO_ACCOUNT_SID
and TWILIO_AUTH_TOKEN
variables in config.py
, respectively.TWILIO_PHONE_NUMBER
variable in config.py
.TWILIO_TO_PHONE
variable to the phone number you want to send notifications to (i.e., your phone number) and setENABLE_TWILIO
to True in config.py
.hackjohn can be run without enabling notifications, which is useful for prototyping and development, but less useful for automated monitoring.
The recommended installation method is to create a virtual environment for just hackjohn. This ensures installation does not modify dependencies for other projects. To install a virtual environment, run the following:
# Create a virtual environment in the env directory
python3 -m venv env
# Activate the virtual environment
source env/bin/activate
# Install the required dependencies into the virtual env
pip install --requirement requirements.txt
# Now you can run hackjohn
python hackjohn.py
You can automate the running of hackjohn.py
at scheduled times every day.
According to the Yosemite permit office, the trailhead quotas are often updated around 11 AM Pacific Time.
I used cron
, which despite its awful interface got the job done.
Therefore, I added the following lines to my crontab
configuration (replacing ABOSOLUTE_REPO_PATH
with the absolute path to the directory containing hackjohn.py
):
# hackjohn bot scheduling (configured for a system on Eastern Time)
0 13 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
44 13 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
59 13 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
14 14 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
30 14 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
40 14 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
00 15 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
19 15 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
00 19 * * * ABOSOLUTE_REPO_PATH/hackjohn.py >> ABOSOLUTE_REPO_PATH/hackjohn.log
Run crontab -e
to edit your cron configuration.
In order to for the cron-scheduled script to run in the proper environment, you must add a shebang pointing to which Python to use.
For example, replace the following with the output of which python
when you have activated the right environment:
#!/home/username/path/to/hackjohn/env/bin/python