Skip to content

Instantly share code, notes, and snippets.

@marcus-deans
Forked from jimmyjxiao/GymScheduler.py
Created August 26, 2021 05:12
Show Gist options
  • Save marcus-deans/9a36ed89c4819d4ebaccbfbaf70821c2 to your computer and use it in GitHub Desktop.
Save marcus-deans/9a36ed89c4819d4ebaccbfbaf70821c2 to your computer and use it in GitHub Desktop.
This script automatically reserves Wilson weightlifting slots.
# This script automatically reserves Wilson weightlifting slots.
# usage: python GymScheduler.py --day=monday --startTime=9:20AM
# use cron (unix) or TaskScheduler (windows) to get this to run automatically 48 hours before
# you need selenium webdriver for chrome and selenium python bindings installed.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import sys, getopt
import datetime
import os
netId = "replaceWithNetId";
password = "replaceWithPassword";
day = "";
timeStr = "";
for opt, arg in getopt.getopt(sys.argv[1:],'', ['day=', 'startTime='])[0]:
if opt == '--day':
day = arg;
elif opt == '--startTime':
timeStr = arg;
time = datetime.datetime.strptime(timeStr, "%I:%M%p");
assert day in ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
url = "";
if(day == "friday"):
url = "https://myrec.recreation.duke.edu/Program/GetProgramDetails?courseId=07f09bf6-a9c9-412c-b829-21527ae9115b&semesterId=b5eb2dd5-ffd9-458e-946d-230f7857a3c3";
elif(day == "saturday"):
url = "https://myrec.recreation.duke.edu/Program/GetProgramDetails?courseId=f0f24306-8ce5-477c-8811-4375143e1236&semesterId=b5eb2dd5-ffd9-458e-946d-230f7857a3c3";
else:
if time < datetime.datetime(1900, 1, 1, 10, 0): # block A
url = "https://myrec.recreation.duke.edu/Program/GetProgramDetails?courseId=394e79ad-b8cc-4766-b624-0a915ffd21f7&semesterId=b5eb2dd5-ffd9-458e-946d-230f7857a3c3";
elif time < datetime.datetime(1900, 1, 1, 13, 0): # block B
url = "https://myrec.recreation.duke.edu/Program/GetProgramDetails?courseId=2e5bb146-2047-408c-841f-f38d5048e86c&semesterId=b5eb2dd5-ffd9-458e-946d-230f7857a3c3";
else: # block C
url = "https://myrec.recreation.duke.edu/Program/GetProgramDetails?courseId=91e8d35c-4c8b-4375-87b7-32b335246157&semesterId=b5eb2dd5-ffd9-458e-946d-230f7857a3c3";
browser = webdriver.Chrome();
browser.get(url);
browser.find_element_by_id("loginLink").click();
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "expand-netid"))).click();
WebDriverWait(browser, 10).until(EC.visibility_of(browser.find_element_by_id("j_username"))).send_keys(netId);
browser.find_element_by_id("j_password").send_keys(password);
browser.find_element_by_id("Submit").click();
strftimeFormatStr = "";
if os.name == 'nt':
strftimeFormatStr = "%#I:%M %p - ";
else:
strftimeFormatStr = "%-I:%M %p - ";
xpath = "//label[contains(text(), '%s')]/..//SMALL[contains(text(), '%s')]/../..//button[text()='Register']" % (day.capitalize(), time.strftime(strftimeFormatStr));
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "gdpr-cookie-accept"))).click();
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, xpath))).click();
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".container-fluid > .btn-primary"))).click();
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.ID, "checkoutButton"))).click();
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".modal-footer > .btn-primary"))).click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment