This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getZipListings(link): | |
# Open the driver | |
driver = webdriver.Chrome(executable_path="/Users/erikgregorywebb/Downloads/chromedriver 2") | |
driver.get(link) | |
# Prepare the vectors | |
titles = [] | |
dates = [] | |
prices = [] | |
bedrooms = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
housing = pd.DataFrame() | |
for link in base_links: | |
time.sleep(5) | |
try: | |
temp = getZipListings(link) | |
temp = temp.merge(zipcodes, on ='Zipcode', how='left') | |
housing = pd.concat([housing, temp]) | |
except: | |
time.sleep(120) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### NYC Housing Search ### | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
import pandas as pd | |
# Read in NYC Zip Codes | |
zipcodes = pd.read_csv("/Users/erikgregorywebb/Documents/Python/nyc-housing/Data/nyc-zip-codes.csv") | |
zipcodes.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Call the Modules | |
import googlemaps | |
import datetime as t | |
import pandas as pd | |
import time | |
# Read in NYC Zip Codes | |
zipcodes = pd.read_csv("/Users/erikgregorywebb/Documents/Python/nyc-housing/Data/nyc-zip-codes.csv") | |
zips = zipcodes['Zipcode'] | |
zipcodes.head() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# authenticate and connect to the API | |
client_id = 'YOUR-CLIENT-ID-HERE' | |
client_secret = 'YOUR-CLIENT-SECRET-HERE' | |
client_credentials_manager = SpotifyClientCredentials(client_id, client_secret) | |
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import libraries | |
import spotipy | |
from spotipy.oauth2 import SpotifyClientCredentials | |
import pandas as pd | |
import time |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get track ids from playlist | |
def getPlaylistTrackIDs(user, playlist_id): | |
ids = [] | |
playlist = sp.user_playlist(user, playlist_id) | |
for item in playlist['tracks']['items']: | |
track = item['track'] | |
ids.append(track['id']) | |
return ids | |
ids = getPlaylistTrackIDs('100keepit', '5w99BzxT7OOCz2oEkKCReG') # Drake Complete |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get song info and audio analysis from song ids | |
def getTrackFeatures(id): | |
meta = sp.track(id) | |
features = sp.audio_features(id) | |
# Meta | |
name = meta['name'] | |
album = meta['album']['name'] | |
artist = meta['album']['artists'][0]['name'] | |
release_date = meta['album']['release_date'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop over track ids to create dataset | |
tracks = [] | |
for i in range(0, 5): | |
time.sleep(.5) | |
track = getTrackFeatures(ids[i]) | |
tracks.append(track) | |
df = pd.DataFrame(tracks, columns = ['name', 'album', 'artist', 'release_date', 'length', 'popularity', 'danceability', 'acousticness', 'danceability', 'energy', 'instrumentalness', 'liveness', 'loudness', 'speechiness', 'tempo', 'time_signature']) | |
df.to_csv("/Users/erikgregorywebb/Documents/Python/spotify/drake.csv", sep = ',') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import libraries | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
import time | |
import pandas as pd | |
import googlemaps |