2018-12-27 16:57:25 +03:00
import urllib
2019-02-20 20:22:45 +03:00
import database
2019-05-01 12:20:40 +03:00
from malojatime import today , thisweek , thismonth , thisyear
2018-12-27 16:57:25 +03:00
2019-03-29 21:44:42 +03:00
2019-02-21 11:43:35 +03:00
def instructions ( keys ) :
2019-03-12 13:39:36 +03:00
from utilities import getArtistImage , getTrackImage
2019-04-08 14:04:31 +03:00
from htmlgenerators import artistLinks
2019-04-08 15:07:37 +03:00
from urihandler import compose_querystring , uri_to_internal
2019-04-23 19:08:37 +03:00
from htmlmodules import module_scrobblelist , module_pulse , module_performance
2018-12-27 16:57:25 +03:00
2019-03-29 21:44:42 +03:00
2019-04-08 14:04:31 +03:00
filterkeys , _ , _ , _ = uri_to_internal ( keys , forceTrack = True )
2019-03-29 21:44:42 +03:00
2019-02-20 20:22:45 +03:00
track = filterkeys . get ( " track " )
2019-03-12 13:39:36 +03:00
imgurl = getTrackImage ( track [ " artists " ] , track [ " title " ] , fast = True )
2019-02-17 16:25:40 +03:00
pushresources = [ { " file " : imgurl , " type " : " image " } ] if imgurl . startswith ( " / " ) else [ ]
2019-03-29 21:44:42 +03:00
2019-06-13 12:37:42 +03:00
data = database . trackInfo ( track )
2019-03-29 21:44:42 +03:00
2019-02-20 20:22:45 +03:00
scrobblesnum = str ( data [ " scrobbles " ] )
pos = " # " + str ( data [ " position " ] )
2019-03-29 21:44:42 +03:00
2019-06-13 13:12:47 +03:00
html_cert = " "
if data [ " certification " ] is not None :
html_cert = " <img class= ' certrecord ' src= ' /media/record_ {cert} .png ' title= ' This track has reached {certc} status ' /> " . format ( cert = data [ " certification " ] , certc = data [ " certification " ] . capitalize ( ) )
2019-02-20 20:22:45 +03:00
2019-04-04 22:29:03 +03:00
html_medals = " "
if " medals " in data and data [ " medals " ] is not None :
if " gold " in data [ " medals " ] :
for y in data [ " medals " ] [ " gold " ] :
2019-04-09 14:34:06 +03:00
html_medals + = " <a title= ' Best Track in " + str ( y ) + " ' class= ' hidelink medal shiny gold ' href= ' /charts_tracks?max=50&in= " + str ( y ) + " ' ><span> " + str ( y ) + " </span></a> "
2019-04-04 22:29:03 +03:00
if " silver " in data [ " medals " ] :
for y in data [ " medals " ] [ " silver " ] :
2019-04-09 14:34:06 +03:00
html_medals + = " <a title= ' Second Best Track in " + str ( y ) + " ' class= ' hidelink medal shiny silver ' href= ' /charts_tracks?max=50&in= " + str ( y ) + " ' ><span> " + str ( y ) + " </span></a> "
2019-04-04 22:29:03 +03:00
if " bronze " in data [ " medals " ] :
for y in data [ " medals " ] [ " bronze " ] :
2019-04-09 14:34:06 +03:00
html_medals + = " <a title= ' Third Best Track in " + str ( y ) + " ' class= ' hidelink medal shiny bronze ' href= ' /charts_tracks?max=50&in= " + str ( y ) + " ' ><span> " + str ( y ) + " </span></a> "
2019-04-04 22:29:03 +03:00
2019-04-23 18:55:59 +03:00
html_scrobbles , _ , _ = module_scrobblelist ( track = track , max_ = 10 , earlystop = True ) # we have the number already from the trackinfo
2019-03-29 21:44:42 +03:00
2019-02-20 20:22:45 +03:00
html_pulse = module_pulse ( track = track , step = " year " , stepn = 1 , trail = 1 )
2019-04-23 19:08:37 +03:00
html_performance = module_performance ( track = track , step = " year " , stepn = 1 , trail = 1 )
2019-02-20 20:22:45 +03:00
2019-05-01 12:20:40 +03:00
# pulse and rankings
html_pulse_days = module_pulse ( track = track , max_ = 7 , since = today ( ) . next ( - 6 ) , step = " day " , trail = 1 )
html_pulse_weeks = module_pulse ( track = track , max_ = 12 , since = thisweek ( ) . next ( - 11 ) , step = " week " , trail = 1 )
html_pulse_months = module_pulse ( track = track , max_ = 12 , since = thismonth ( ) . next ( - 11 ) , step = " month " , trail = 1 )
html_pulse_years = module_pulse ( track = track , max_ = 10 , since = thisyear ( ) . next ( - 9 ) , step = " year " , trail = 1 )
html_performance_days = module_performance ( track = track , max_ = 7 , since = today ( ) . next ( - 6 ) , step = " day " , trail = 1 )
html_performance_weeks = module_performance ( track = track , max_ = 12 , since = thisweek ( ) . next ( - 11 ) , step = " week " , trail = 1 )
html_performance_months = module_performance ( track = track , max_ = 12 , since = thismonth ( ) . next ( - 11 ) , step = " month " , trail = 1 )
html_performance_years = module_performance ( track = track , max_ = 10 , since = thisyear ( ) . next ( - 9 ) , step = " year " , trail = 1 )
2018-12-27 16:57:25 +03:00
2019-04-23 18:55:59 +03:00
replace = {
" KEY_TRACKTITLE " : track . get ( " title " ) ,
" KEY_ARTISTS " : artistLinks ( track . get ( " artists " ) ) ,
" KEY_SCROBBLES " : scrobblesnum ,
" KEY_POSITION " : pos ,
" KEY_IMAGEURL " : imgurl ,
" KEY_SCROBBLELINK " : compose_querystring ( keys ) ,
" KEY_MEDALS " : html_medals ,
2019-06-13 13:12:47 +03:00
" KEY_CERTS " : html_cert ,
2019-04-23 18:55:59 +03:00
" KEY_SCROBBLELIST " : html_scrobbles ,
2019-05-01 12:20:40 +03:00
# pulse
" KEY_PULSE_MONTHS " : html_pulse_months ,
" KEY_PULSE_YEARS " : html_pulse_years ,
" KEY_PULSE_DAYS " : html_pulse_days ,
" KEY_PULSE_WEEKS " : html_pulse_weeks ,
# performance
" KEY_PERFORMANCE_MONTHS " : html_performance_months ,
" KEY_PERFORMANCE_YEARS " : html_performance_years ,
" KEY_PERFORMANCE_DAYS " : html_performance_days ,
" KEY_PERFORMANCE_WEEKS " : html_performance_weeks ,
2019-04-23 18:55:59 +03:00
}
2019-03-29 21:44:42 +03:00
2019-02-17 16:25:40 +03:00
return ( replace , pushresources )