Skip to content

Instantly share code, notes, and snippets.

View Sample Histogram
ggplot(moment, aes(x = minuteCount)) +
geom_histogram(binwidth = 10) +
labs(title="Distribution of Minute Counts")
View app.R
# https://unboxed-analytics.shinyapps.io/the-potential-for-growth/
# http://unboxed-analytics.com/life-hacking/fundamentals-of-investing/
library(FinCal)
library(ggplot2)
library(tidyr)
library(shinythemes)
library(scales)
# Define UI for application that draws a histogram
View getListingLinks.py
View getListingContent.py
def getListingContent(listing_link):
# Open the driver
driver = webdriver.Chrome(executable_path="/Users/erikgregorywebb/Downloads/chromedriver 2")
driver.get(listing_link)
# Collect listing informtion
try:
title = driver.find_element_by_css_selector('.listingDetails-title')
location = driver.find_element_by_css_selector('.listingDetails-location')
price = driver.find_element_by_css_selector('.listingDetails-price')
View libraries.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pandas as pd
View getListings.py
def getListings(url):
links = getListingLinks(url)
listings = []
# Loop over each listing link
for i in range(0, 10):
time.sleep(3)
try:
listing = getListingContent(links[i])
listings.append(listing)
View cleanLlistings.py
def cleanLlistings(df):
# Split the location variable into location and days_online
df['location'], df['days_online'] = df['location'].str.split('|', 1).str
# Remove the dollar sign in price
df['price'] = df['price'].str.replace('$', '')
df['price'] = df['price'].str.replace(',', '')
# Convert from string to numeric
df['views'] = pd.to_numeric(df['views'])
View main.py
def main(url):
start_time = time.time()
# Process
raw_df = getListings(url)
df = cleanLlistings(raw_df)
# Export
df.to_csv("/Users/erikgregorywebb/Documents/Python/ksl-scrapper/listings.csv", sep = ',')
View ksl-scraper.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import pandas as pd
def getListingLinks(link):
# Open the driver
driver = webdriver.Chrome(executable_path="/Users/erikgregorywebb/Downloads/chromedriver 2")
driver.get(link)
View nyc-housing.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.