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

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 tracks for last 7 days


In [ ]:
nbDays = '7'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))

Top 10 tracks for last 30 days


In [ ]:
nbDays = '30'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))

Top 10 tracks for last 90 days


In [ ]:
nbDays = '90'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))

Top 10 tracks for last 120 days


In [ ]:
nbDays = '120'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))

Top 10 tracks for last 180 days


In [ ]:
nbDays = '180'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))

Top 10 tracks for last 365 days


In [ ]:
nbDays = '365'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))

Top 10 tracks for all time


In [ ]:
nbDays = 'null'
df = lf.retrieve_top_tracks_as_dataframe(cursor, nbDays, 10)

iplot(lf.create_figure(df.Track, df.ArtistAlbumTrack, df.PlayCount, 'tracks', nbDays))