Skip to content

Instantly share code, notes, and snippets.

hamletbatista

Block or report user

Report or block hamletbatista

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View visualize_final_reframe.py
data = []
ages = ["Pre-K", "Grade School", "Teens", "Young Adults", "Over 30", "Seniors"]
top_5 = []
for i in range(5):
scores = []
for age in ages:
scores.append(tuple(rides.sort_values(age, ascending=False)[[age, "Ride"]].iloc[i].values))
top_5.append(scores)
View get_disney_ride_ratings.py
# Get Disney Attractiveness Ratings
import requests
from bs4 import BeautifulSoup
r = requests.get("https://touringplans.com/disneyland/attractions")
soup = BeautifulSoup(r.text)
rows = []
table = soup.find("table")
for idx, tr in enumerate(table.findAll("tr")):
View enjoyment_score.py
# Data taken from here: https://touringplans.com/disneyland/attractions
# Ties in attraction ratings were resolved by selecting the age group closest to the next-highest score
df['Age Group'] = ["Pre-K", "Grade School", "Seniors",
"Pre-K", "Seniors", "Seniors",
"Pre-K", "Grade School", "Over 30",
"Seniors", "Pre-K", "Pre-K",
"Teens", "Teens", "Seniors",
"Young Adults", "Young Adults", "Teens",
"Pre-K", "Pre-K"]
View visualize_ridetimes.py
#!pip install plotly-express
import pandas as pd
from urllib.parse import urlparse
from collections import Counter
import plotly.express as px
import plotly
import plotly.graph_objects as go
fig = px.scatter(df, x="Average Wait Time", y="Ride Duration", color="Ride", symbol="Ride", height=900, width=1200)
View avgwaittimeandduration.py
average_wait=pd.Series(df.mean(), name="Average Wait Time")
print(average_wait)
#example output
#Astro Orbitor 12.453125
#Buzz Lightyear Astro Blasters 17.953125
duration = pd.Series(ride_durations, name="Ride Duration")
print(duration)
View ridewaittimesjs2py.py
from jinja2 import Template
js_template="""
function drawChart137() {
var columns = {{columns}};
var title = "{{title}}";
return [title, columns];
}
View ridewaittimes.py
script_sel="#new_gchart_slideshow > div.forecast-viewport > ul > li > script"
all_rides = r.html.find(script_sel)
def extract_dates(data):
start_row = "dateData.addRows\("
end_row = "\);"
columns = []
title = None
View ridesduration.py
r = session.get('https://touringplans.com/disneyland/attractions/duration')
ride_durations = dict()
for tr in r.html.find("#center > table > tr"): #element selected copied from Chrome Developer Tools
ride = tr.find("td:nth-child(1)")[0].text
duration = tr.find("td:nth-child(2)")[0].text
print(ride, duration)
View caption_all_images.py
captions = dict()
for image_url in unique_images:
try:
caption = generate_caption(image_url)
captions[image_url] = caption
View clean_image_urls_part1.py
import re
i = len(df["Custom Extraction 1"])#.split('<img src="')
images = list()
for i, image_list in enumerate(df["Custom Extraction 1"]):
#print(i)
images.extend(df["Custom Extraction 1"][i].split('<img src="'))
You can’t perform that action at this time.