In [ ]:
import MySQLdb
import netrc
import pandas
import lastfmDb as lf
import datetime

from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

init_notebook_mode(connected=True)

login = netrc.netrc().authenticators('lastfm.mysql')
if not login:
    raise netrc.NetrcParseError('No authenticators for lastfm.mysql')

mysql = MySQLdb.connect(user=login[0],passwd=login[2],db=login[1], charset='utf8')
cursor = mysql.cursor()

Last execution date and time


In [ ]:
today = datetime.datetime.now()
print today.strftime('Generated on the %d %b %Y at %H:%M:%S')

Play count for year


In [ ]:
forYear = 2016
lf.retrieve_total_play_count_for_year(cursor, forYear)

Top 10 artists for year


In [ ]:
df = lf.retrieve_top_artists_for_year_as_dataframe(cursor, forYear, 20)
top10 = df.head(10)

iplot(lf.create_figure_for_year(top10.Artist, top10.Artist, top10.PlayCount, 'artists', forYear))

In [ ]:
df

Top 10 albums for year


In [ ]:
df = lf.retrieve_top_albums_for_year_as_dataframe(cursor, forYear, 20)
top10 = df.head(10)

iplot(lf.create_figure_for_year(top10.Album, top10.Album, top10.PlayCount, 'albums', forYear))

In [ ]:
df

Top 10 tracks for year


In [ ]:
df = lf.retrieve_top_tracks_for_year_as_dataframe(cursor, forYear, 20)
top10 = df.head(10)

iplot(lf.create_figure_for_year(top10.Track, top10.Track, top10.PlayCount, 'tracks', forYear))

In [ ]:
df