def testChartsYearEnd(self): """Checks that the function for listing all year-end charts returns reasonable results.""" charts = billboard.charts(year_end=True) chart_names = ["top-artists", "radio-songs", "top-country-albums"] for name in chart_names: self.assertTrue(name in charts) self.assertTrue(300 <= len(charts) <= 500)
def testCharts(self): """Checks that the function for listing all charts returns reasonable results.""" charts = billboard.charts() self.assertTrue("hot-100" in charts) self.assertTrue(200 <= len(charts) <= 400)
def get_billboard_charts(self): return billboard.charts()
#--------------Grab all chart categories, and initialize the script to today = datetime.today() NULL_GENRES = [ 'country', 'contemporary', 'rock', 'alternative', 'tropical', 'mexican', 'christian', 'gospel', 'classical', 'new-age', 'blues', 'folk', 'reggae', 'bluegrass', 'cast', 'comedy', 'canadian' ] if today.month == 12: final_year = today.year + 1 else: final_year = today.year TYPES = ['artist', 'producer', 'songs', 'album'] ALL_YEAREND_CHART_CATEGORIES = billboard.charts(year_end=True) years = list(range(2010, final_year)) #--------------Loops through all the different chart types for YEC_Cat in ALL_YEAREND_CHART_CATEGORIES: for ty in TYPES: #--------------Filters down to only releavant charts (Artists, Producers, Albums, Songs) if ty in YEC_Cat and 'imprints' not in YEC_Cat and 'label' not in YEC_Cat and not any( gen in YEC_Cat for gen in NULL_GENRES): print(YEC_Cat) YEC_SQL_Dict = {} #--------------For each year, grabs that chart's attributes and corresponding entries and enters them into the database for year in years: print(year) # try:
def preview_link(track_name, name): track = spotify.search(track_name, limit=1, offset=0, type='track', market=None) items = track['tracks']['items'] artist = track['tracks']['items'][0]['artists'][0]['name'] link = items[0]['preview_url'] #lyrics = genius.search_song(track_name, artist) if (str(link) != 'None'): val.append([str(track_name), str(link), str(artist), str(name)]) return val all_chart = list(billboard.charts()) out = [] #for i in range(0,10): name = 'hot-100' chart = billboard.ChartData(name) print(chart[0].title, chart[0].artist) def allcharts(): return chart def lyrics(song): lyrics = str(song.lyrics) return lyrics
import billboard as bb count = 0 for chart in bb.charts(): # get only song charts. don't include greatest or streaming if chart.endswith( "-songs") and "greatest" not in chart and "streaming" not in chart: print(chart) count += 1 print(count) # Picked these genres: """pop-songs, country-songs, rock-songs, alternative-songs, r-b-hip-hop-songs, dance-electronic-songs, christian-songs, jazz-songs"""
import billboard import mysql.connector import random cnx = mysql.connector.connect(user='******', password='', host='127.0.0.1', database='XXXX') cursor = cnx.cursor() allbb = billboard.charts() def ins(val): sql = """INSERT INTO playlist (playlist) VALUES (%s)""" values = tuple(val) cursor.execute(sql, values) cnx.commit() for i in range(len(allbb)): ins([str(allbb[i])])