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 by month


In [ ]:
df = lf.retrieve_play_count_by_month_as_dataframe(cursor)
df.head()

Top 10 artists for last 7 days


In [ ]:
nbDays = '7'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df

Top 10 artists for last 30 days


In [ ]:
nbDays = '30'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df

Top 10 artists for last 90 days


In [ ]:
nbDays = '90'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df

Top 10 artists for last 120 days


In [ ]:
nbDays = '120'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df

Top 10 artists for last 180 days


In [ ]:
nbDays = '180'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df

Top 10 artists for last 365 days


In [ ]:
nbDays = '365'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df

Top 10 artists for all time


In [ ]:
nbDays = 'null'
df = lf.retrieve_top_artists_as_dataframe(cursor, nbDays, 20)
top10 = df.head(10)

iplot(lf.create_figure(top10.Artist, top10.Artist, top10.PlayCount, 'artists', nbDays))

In [ ]:
df