Skip to content

Instantly share code, notes, and snippets.

@tommyjtl
Created June 4, 2022 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommyjtl/e75fa2d0789bbf4ace979779426b6350 to your computer and use it in GitHub Desktop.
Save tommyjtl/e75fa2d0789bbf4ace979779426b6350 to your computer and use it in GitHub Desktop.
Periodically checking reservation slots for Yosemite National Park Ticketed Entry.
# pm2 start yosemite-reservation-check.py --name yosemite --interpreter python
import http.client
import json, time, threading
to_query_dates = ["2022-06-07", "2022-06-08", "2022-06-09"] # Follow the format: YYYY-MM-DD
query_period = 300 # seconds
def query():
conn = http.client.HTTPSConnection("www.recreation.gov")
# Change year and month accordingly
conn.request("GET", "/api/timedentry/availability/facility/10086745/monthlyAvailabilitySummaryView?year=2022&month=06&inventoryBucket=FIT&tourID=10086746", "")
res = conn.getresponse()
data = res.read()
data_json = json.loads(data.decode("utf-8"))
return data_json
def query_date(result, date):
try:
return result["facility_availability_summary_view_by_local_date"][date]["availability_level"]
except BaseException as e:
print(e)
return str(e)
def alert(payload):
conn = http.client.HTTPSConnection("maker.ifttt.com")
headers = { 'Content-Type': "application/json" }
# Change XXXXXXXXXXXXXXXXXXXXXX to your own API key on https://ifttt.com/maker_webhooks
conn.request("POST", "/trigger/yosemite_reservation/json/with/key/XXXXXXXXXXXXXXXXXXXXXX", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
def event():
print("+--------------------------+")
print("|", time.ctime(), "|")
print("+--------------------------+")
query_result = query()
alert_payload = {"availability": []}
for date in to_query_dates:
print(date, query_date(query_result, date))
alert_payload["availability"].append({date: query_date(query_result, date)})
print(alert_payload)
for date in to_query_dates:
if query_date(query_result, date) != "NONE":
alert(json.dumps(alert_payload))
threading.Timer(query_period, event).start()
event()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment