Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
def get_album_tracks(album_id):
"""
Returns: dictionary object.
Track ids as keys, track names as values.
"""
tracks = []
results = sp.album_tracks(album_id)
tracks.extend(results['items'])
# By default album_tracks function can obtain up to 50 item from spotify API in one try.
# If there is more than 50 items, this function will return 'next'.
@badalnabizade
badalnabizade / artist_albums.py
Created August 19, 2019 14:45
Get albums data for each artist.
def get_artist_albums(artist):
"""
----------
artist: artist's information that obtained by get_artist function.
----------
Returns: dictionary object.
Album names as keys, album ids as values.
"""
albums = []
results = sp.artist_albums(artist['id'], album_type='album')
@badalnabizade
badalnabizade / get_artists.py
Created August 19, 2019 14:29
Getting artists data from Spotify API:
def get_artist(name):
"""
----------
name: 'Name of Spotify artist'
----------
Returns: dictionary object.
Given Spotify Artist's information.
"""
results = sp.search(q='artist:' + name, type='artist')
items = results['artists']['items']
@badalnabizade
badalnabizade / user_playlists.py
Last active August 19, 2019 14:00
Extracting user's playlist data from Spotify API.
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
with open('app_token.txt', 'r') as file:
tokens = file.read()
token_dict = json.loads(tokens)
client_credentials_manager = \
SpotifyClientCredentials(client_id=token_dict['client_id'],
movie_names = movies.set_index('movieId')['title'].to_dict()
g=ratings.groupby('movieId')['rating'].count()
#TopMovies are top 3000 movies that got more user reviews than others.
topMovies=g.sort_values(ascending=False).index.values[:3000]
uniq = ratings.movieId.unique() # Ids of unique movies.
name2idx = {o:i for i,o in enumerate(uniq)}
topMovieIdx = np.array([name2idx[o] for o in topMovies]) # Indices of top rated movies in ratings.csv
import pandas as pd
import numpy as np
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
from tensorflow.keras.layers import Input, add, dot, Flatten, Embedding,Dropout, concatenate
from tensorflow.keras.regularizers import l2
from tensorflow.keras import optimizers
ratings = pd.read_csv('./data/ratings.csv')
ratings.drop('timestamp', 1, inplace=True)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@badalnabizade
badalnabizade / home_price_project.ipynb
Created February 6, 2019 09:18
antalya_home_price
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.