2019-02-02 18:54:01 +03:00
import urllib
2019-02-18 19:22:44 +03:00
from datetime import datetime
2019-02-21 02:13:18 +03:00
import database
2019-02-02 18:54:01 +03:00
2019-02-20 20:22:45 +03:00
from htmlmodules import module_scrobblelist , module_pulse
2019-02-02 18:54:01 +03:00
2019-02-21 11:43:35 +03:00
def instructions ( keys ) :
2019-02-04 15:45:51 +03:00
from utilities import getArtistsInfo , getTracksInfo
2019-02-19 16:57:39 +03:00
from htmlgenerators import artistLink , artistLinks , trackLink , scrobblesArtistLink , scrobblesLink , keysToUrl , pickKeys , clean , getTimeDesc , getRangeDesc
2019-02-02 18:54:01 +03:00
2019-02-21 02:13:18 +03:00
max_show = 14
posrange = [ " # " + str ( i ) for i in range ( 1 , max_show + 1 ) ]
2019-02-02 18:54:01 +03:00
# get chart data
2019-02-02 20:08:30 +03:00
# artists
2019-02-21 02:13:18 +03:00
charts = database . get_charts_artists ( ) [ : max_show ]
2019-02-02 20:08:30 +03:00
artisttitles = [ c [ " artist " ] for c in charts ]
2019-02-20 23:10:58 +03:00
artistimages = [ " /image?artist= " + urllib . parse . quote ( a ) for a in artisttitles ]
2019-02-02 20:08:30 +03:00
artistlinks = [ artistLink ( a ) for a in artisttitles ]
2019-02-02 18:54:01 +03:00
2019-02-02 20:08:30 +03:00
# tracks
2019-02-21 02:13:18 +03:00
charts = database . get_charts_tracks ( ) [ : max_show ]
2019-02-02 20:08:30 +03:00
trackobjects = [ t [ " track " ] for t in charts ]
tracktitles = [ t [ " title " ] for t in trackobjects ]
2019-02-20 23:10:58 +03:00
trackimages = [ " /image?title= " + urllib . parse . quote ( t [ " title " ] ) + " & " + " & " . join ( [ " artist= " + urllib . parse . quote ( a ) for a in t [ " artists " ] ] ) for t in trackobjects ]
2019-02-02 20:08:30 +03:00
tracklinks = [ trackLink ( t ) for t in trackobjects ]
# get scrobbles
2019-02-20 20:22:45 +03:00
html_scrobbles , _ , _ = module_scrobblelist ( max_ = 15 , shortTimeDesc = True , pictures = True )
2019-02-03 18:52:37 +03:00
2019-02-02 20:08:30 +03:00
# get stats
2019-02-21 02:13:18 +03:00
amount = database . get_scrobbles_num ( since = " today " )
scrobbles_today = " <a href= ' /scrobbles?since=today ' > " + str ( amount ) + " </a> "
2019-02-02 20:08:30 +03:00
2019-02-21 02:13:18 +03:00
amount = database . get_scrobbles_num ( since = " month " )
scrobbles_month = " <a href= ' /scrobbles?since=month ' > " + str ( amount ) + " </a> "
amount = database . get_scrobbles_num ( since = " year " )
scrobbles_year = " <a href= ' /scrobbles?since=year ' > " + str ( amount ) + " </a> "
amount = database . get_scrobbles_num ( )
scrobbles_total = " <a href= ' /scrobbles ' > " + str ( amount ) + " </a> "
2019-02-02 18:54:01 +03:00
2019-02-15 17:18:57 +03:00
2019-02-18 19:22:44 +03:00
# get pulse
dt = datetime . utcnow ( )
dtl = [ dt . year - 1 , dt . month + 1 ]
if dtl [ 1 ] > 12 : dtl = [ dtl [ 0 ] + 1 , dtl [ 1 ] - 12 ]
dts = " / " . join ( [ str ( e ) for e in dtl ] )
# this is literally the ugliest piece of code i have written in my entire feckin life
# good lord
2019-02-20 20:22:45 +03:00
html_pulse = module_pulse ( max_ = 12 , since = dts , step = " month " , trail = 1 )
2019-02-21 02:13:18 +03:00
pushresources = [ { " file " : img , " type " : " image " } for img in artistimages + trackimages ] #can't push scrobble images as we don't get them from the module function, need to think about that
2019-02-04 15:45:51 +03:00
2019-02-17 16:25:40 +03:00
replace = { " KEY_ARTISTIMAGE " : artistimages , " KEY_ARTISTNAME " : artisttitles , " KEY_ARTISTLINK " : artistlinks , " KEY_POSITION_ARTIST " : posrange ,
2019-02-02 20:08:30 +03:00
" KEY_TRACKIMAGE " : trackimages , " KEY_TRACKNAME " : tracktitles , " KEY_TRACKLINK " : tracklinks , " KEY_POSITION_TRACK " : posrange ,
2019-02-03 18:52:37 +03:00
" KEY_SCROBBLES_TODAY " : scrobbles_today , " KEY_SCROBBLES_MONTH " : scrobbles_month , " KEY_SCROBBLES_YEAR " : scrobbles_year , " KEY_SCROBBLES_TOTAL " : scrobbles_total ,
2019-02-20 20:22:45 +03:00
#"KEY_SCROBBLE_TIME":scrobbletimes,"KEY_SCROBBLE_ARTISTS":scrobbleartists,"KEY_SCROBBLE_TITLE":scrobbletracklinks,"KEY_SCROBBLE_IMAGE":scrobbleimages,
" KEY_SCROBBLES " : html_scrobbles ,
#"KEY_PULSE_TERM":pulse_rangedescs,"KEY_PULSE_AMOUNT":pulse_amounts,"KEY_PULSE_BAR":pulse_bars
" KEY_PULSE " : html_pulse
}
2019-02-17 16:25:40 +03:00
return ( replace , pushresources )
2019-02-02 18:54:01 +03:00