Skip to content

Commit 3bd04f2

Browse files
committed
Add Disneyland itinerary optimization example using GAMSPy
1 parent acc6225 commit 3bd04f2

15 files changed

+20776
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

notebooks/.DS_Store

6 KB
Binary file not shown.
6 KB
Binary file not shown.
6 KB
Binary file not shown.

notebooks/disneyland_itinerary/Data/cleaned_wait_times_2024_10_29.csv

Lines changed: 34 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
,Ride Duration
2+
Astro Orbiter,1 minute 30 seconds
3+
Barnstormer,1 minute 3 seconds
4+
Big Thunder Mountain Railroad,3 minutes 25 seconds
5+
Buzz Lightyear's Space Ranger Spin,4 minutes 3 seconds
6+
Carousel of Progress,20 minutes 45 seconds
7+
Country Bear Jamboree,12 minutes
8+
Dumbo the Flying Elephant,1 minute 30 seconds
9+
Enchanted Tiki Room,10 minutes
10+
The Hall of Presidents,21 minutes 35 seconds
11+
Haunted Mansion,7 minutes 30 seconds
12+
it's a small world,10 minutes 30 seconds
13+
Jungle Cruise,9 minutes 5 seconds
14+
Liberty Square Riverboat,12 minutes 45 seconds
15+
Mad Tea Party,1 minute 30 seconds
16+
Magic Carpets of Aladdin,1 minute 30 seconds
17+
Many Adventures of Winnie the Pooh,3 minutes 8 seconds
18+
Mickey's PhilharMagic,12 minutes
19+
Monster's Inc. Laugh Floor,11 minutes
20+
Peter Pan's Flight,2 minutes 45 seconds
21+
Pirates of the Caribbean,8 minutes 30 seconds
22+
Prince Charming's Royal Carrousel,2 minutes
23+
Seven Dwarfs Mine Train,2 minutes 30 seconds
24+
Space Mountain,2 minutes 30 seconds
25+
Splash Mountain,11 minutes
26+
Swiss Family Treehouse,13 minutes 5 seconds
27+
Tomorrowland Indy Speedway,4 minutes 45 seconds
28+
Tomorrowland Transit Authority Peoplemover,10 minutes 4 seconds
29+
Under the Sea ~ Journey of the Little Mermaid,6 minutes 15 seconds
30+
Walt Disney World Railroad,20 minutes
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
,Ride Duration,Source
2+
Orbiter,15,
3+
Barnstormer,1.05,
4+
Big Thunder Mtn.,3.416666667,
5+
Buzz SRS,4.05,
6+
Dumbo,1.5,
7+
Enchanted Tales,20,https://plandisney.disney.go.com/question/long-experience-enchanted-tales-belle-407817/
8+
Mansion,7.5,
9+
Small World,10.5,
10+
Jungle Cruise,9.083333333,
11+
Mad Tea Party,1.5,
12+
Magic Carpets,1.5,
13+
Winnie the Pooh,3.133333333,
14+
Ariel Grotto,3,https://touringplans.com/magic-kingdom/attractions/ariels-grotto
15+
Cinderella & Princess,10,https://touringplans.com/magic-kingdom/attractions/princess-fairytale-hall-cinderella
16+
Daring Show,7,https://touringplans.com/magic-kingdom/attractions/petes-silly-sideshow-goofy-donald
17+
Dashing Show,3,https://touringplans.com/magic-kingdom/attractions/petes-silly-sideshow-minnie-daisy
18+
Mickey Town Theater,12,https://www.undercovertourist.com/orlando/magic-kingdom/mickey-mouse-town-square-theater-character/
19+
Princess Tiana & Princess,10,https://touringplans.com/magic-kingdom/attractions/princess-fairytale-hall-rapunzel-tiana
20+
Philharmonic,12,
21+
Laugh Floor,11,
22+
Peter Pan's Flight,2.75,
23+
Pirates,8.5,
24+
Regal Carrousel,2,
25+
Seven Dwarfs Mine Train,2.5,
26+
Space Mtn.,2.5,
27+
Tiana Bayou Adv.,9,https://darkridedatabase.com/rides/tianas-bayou-adventure/
28+
TL Speedway,4.75,
29+
TL Mover,10.06666667,
30+
TRON,2,https://en.wikipedia.org/wiki/Tron_Lightcycle_Power_Run
31+
Under the Sea,6.25,
32+
Fireworks,16,
33+
Entrance,0,
34+
Exit,0,
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
import pandas as pd
4+
from datetime import datetime, time
5+
import pytz
6+
import os
7+
import time as time_module
8+
9+
def fetch_ride_wait_times():
10+
# URL of the webpage with the Disneyland ride wait times
11+
url = 'https://wdwpassport.com/wait-times/magic-kingdom'
12+
13+
# Set the timezone for Orlando
14+
orlando_tz = pytz.timezone('America/New_York')
15+
16+
# Get the current time in Orlando
17+
crawl_time = datetime.now(orlando_tz).strftime('%Y-%m-%d %H:%M')
18+
19+
# Send a GET request to the website to fetch the HTML content
20+
response = requests.get(url)
21+
22+
# Check if the request was successful
23+
if response.status_code == 200:
24+
# Parse the HTML content using BeautifulSoup
25+
soup = BeautifulSoup(response.text, 'html.parser')
26+
27+
# List to store the ride names and wait times
28+
rides_data = []
29+
30+
# Find all the list items with the ride and wait time information
31+
rides_list = soup.find_all('li', class_='relative flex items-center justify-between border-b border-gray-200 px-4 py-2 last:border-b-0')
32+
33+
# Loop through each ride entry and extract the ride name and wait time
34+
for ride_item in rides_list:
35+
# Extract the ride name (inside <h3> tag)
36+
ride_name = ride_item.find('h3', class_='relative z-10 mr-4 text-sm font-medium leading-tight').text.strip()
37+
38+
# Extract the regular wait time (for most rides)
39+
wait_time_div = ride_item.find('div', class_='inline-flex h-8 w-8 items-center justify-center rounded-full bg-teal-200 font-medium text-teal-800')
40+
41+
# Special case for Tiana's Bayou Adventure wait time format
42+
special_wait_time_div = ride_item.find('div', class_='ml-1 inline-flex h-8 w-8 items-center justify-center whitespace-nowrap rounded-full bg-teal-200 text-base font-medium text-teal-800')
43+
44+
# Determine which wait time div to use (prefer the special one if it exists)
45+
if special_wait_time_div:
46+
wait_time = special_wait_time_div.text.strip()
47+
elif wait_time_div:
48+
wait_time = wait_time_div.text.strip()
49+
else:
50+
wait_time = 'N/A' # Handle cases where wait time is missing
51+
52+
# Append the ride name and wait time to the list
53+
rides_data.append([ride_name, wait_time])
54+
55+
# Create a DataFrame from the scraped data
56+
rides_df = pd.DataFrame(rides_data, columns=['Ride Name', crawl_time])
57+
58+
# Check if the file already exists
59+
file_name = 'wait_times.csv'
60+
if os.path.exists(file_name):
61+
# Read the existing file
62+
existing_df = pd.read_csv(file_name)
63+
64+
# Merge the new data with the existing data based on 'Ride Name'
65+
merged_df = pd.merge(existing_df, rides_df, on='Ride Name', how='left')
66+
67+
# Save the updated dataframe
68+
merged_df.to_csv(file_name, index=False)
69+
print(f"Updated wait times for {crawl_time}.")
70+
else:
71+
# Create a new file with the current data
72+
rides_df.to_csv(file_name, index=False)
73+
print(f"Created a new wait times file for {crawl_time}.")
74+
75+
return rides_df
76+
77+
else:
78+
print(f"Failed to retrieve the webpage. Status code: {response.status_code}")
79+
return None
80+
81+
if __name__ == '__main__':
82+
# Define the Orlando timezone
83+
orlando_tz = pytz.timezone('America/New_York')
84+
85+
while True:
86+
# Get the current time in Orlando
87+
current_time_orlando = datetime.now(orlando_tz).time()
88+
89+
# Define park open and close times
90+
park_open_time = time(7, 00) # Park opens at 07:00 AM
91+
park_close_time = time(0, 30) # Park closes at 23:30 PM (next day)
92+
# fetch_ride_wait_times()
93+
94+
# Check if the current time is within the park's operating hours
95+
if (park_open_time <= current_time_orlando <= time(23, 59)) or (time(0, 0) <= current_time_orlando <= park_close_time):
96+
# if (park_open_time <= current_time_orlando <= park_close_time):
97+
fetch_ride_wait_times() # Fetch and save wait times
98+
else:
99+
print("Park is closed. Skipping fetch.", current_time_orlando)
100+
101+
# Sleep for 5 minutes (300 seconds)
102+
time_module.sleep(300)

0 commit comments

Comments
 (0)