From a939f228427c241b1c1117fc1c98d191221d04bf Mon Sep 17 00:00:00 2001 From: Victor Villas Date: Thu, 29 Aug 2024 13:42:44 -0700 Subject: [PATCH] Update bcparks utility --- {scripts => projects/outdoors}/bcparks.py | 36 ++++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) rename {scripts => projects/outdoors}/bcparks.py (71%) diff --git a/scripts/bcparks.py b/projects/outdoors/bcparks.py similarity index 71% rename from scripts/bcparks.py rename to projects/outdoors/bcparks.py index 10758ca8..ebdb4223 100644 --- a/scripts/bcparks.py +++ b/projects/outdoors/bcparks.py @@ -11,43 +11,37 @@ import os import requests import time -from datetime import datetime, timezone, timedelta from selenium.webdriver import Firefox from selenium.webdriver.common.by import By from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC -logging.basicConfig(level=logging.INFO) - -# TODO: receive form data as input -""" -Example -------- -Rafael -Rodrigues Ghossi -rafael.ghossi@gmail.com - -Natália -Turrioni Tavares -natalia.turrioni@gmail.com -""" +default_headers = { + "Accept": "application/json, text/plain, */*", + "Accept-Language": "en-CA,en-US;q=0.9,en;q=0.8", + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.6 Safari/605.1.15", + "X-App-Version": "3ebc5f89d9acbddc41f8e8bca8bea1ded750d32e", +} class BCParksReservation: def watch(self, date): - while not self.check(date): - time.sleep(2) - os.system('say "Passes are available!"') - self.reserve(date) + while True: + while not self.check(date): + time.sleep(10) + os.system('say "Passes are available!"') + # self.reserve(date) def check(self, date): date = dateparser.parse(date).strftime("%Y-%m-%d") base_url = "jd7n1axqh0.execute-api.ca-central-1.amazonaws.com/api" park_params = "reservation?facility=Joffre%20Lakes&park=0363" - response = requests.get(f"https://{base_url}/{park_params}") + response = requests.get( + f"https://{base_url}/{park_params}", headers=default_headers + ) response = json.loads(response.text) - logging.debug(response) + print(response) capacity = response[date]["DAY"]["capacity"] if capacity == "Full":