2019-02-02 18:54:01 +03:00
import urllib
2019-03-03 15:38:53 +03:00
from datetime import datetime , timedelta
2019-02-21 02:13:18 +03:00
import database
2019-03-29 21:44:42 +03:00
from doreah . timing import clock , clockp
2019-04-09 12:48:12 +03:00
from doreah . settings import get_settings
2019-02-02 18:54:01 +03:00
2019-03-03 23:22:42 +03:00
from htmlmodules import module_scrobblelist , module_pulse , module_artistcharts_tiles , module_trackcharts_tiles
2019-02-20 20:22:45 +03:00
2019-03-18 22:30:28 +03:00
2019-02-21 11:43:35 +03:00
def instructions ( keys ) :
2019-02-21 02:13:18 +03:00
2019-04-09 12:56:09 +03:00
# commands to execute on load for default ranges
js_command = " showRange( ' topartists ' , ' " + get_settings ( " DEFAULT_RANGE_CHARTS_ARTISTS " ) + " ' ); "
js_command + = " showRange( ' toptracks ' , ' " + get_settings ( " DEFAULT_RANGE_CHARTS_TRACKS " ) + " ' ); "
js_command + = " showRange( ' pulse ' , ' " + get_settings ( " DEFAULT_RANGE_PULSE " ) + " ' ); "
2019-03-04 15:43:19 +03:00
2019-04-10 19:50:56 +03:00
clock ( )
2019-03-11 22:04:23 +03:00
2019-04-11 13:07:57 +03:00
from malojatime import today , thisweek , thismonth , thisyear
2019-02-02 20:08:30 +03:00
# artists
2019-03-18 22:30:28 +03:00
2019-03-03 23:22:42 +03:00
topartists_total = module_artistcharts_tiles ( )
2019-04-11 13:07:57 +03:00
topartists_year = module_artistcharts_tiles ( timerange = thisyear ( ) )
topartists_month = module_artistcharts_tiles ( timerange = thismonth ( ) )
topartists_week = module_artistcharts_tiles ( timerange = thisweek ( ) )
2019-03-18 22:30:28 +03:00
2019-04-10 19:50:56 +03:00
clockp ( " Artists " )
2019-03-11 22:04:23 +03:00
2019-02-02 20:08:30 +03:00
# tracks
2019-03-18 22:30:28 +03:00
2019-03-03 23:22:42 +03:00
toptracks_total = module_trackcharts_tiles ( )
2019-04-11 13:07:57 +03:00
toptracks_year = module_trackcharts_tiles ( timerange = thisyear ( ) )
toptracks_month = module_trackcharts_tiles ( timerange = thismonth ( ) )
toptracks_week = module_trackcharts_tiles ( timerange = thisweek ( ) )
2019-03-18 22:30:28 +03:00
2019-04-10 19:50:56 +03:00
clockp ( " Tracks " )
2019-03-11 22:04:23 +03:00
2019-04-09 12:56:09 +03:00
2019-04-09 12:48:12 +03:00
2019-03-11 22:04:23 +03:00
2019-03-04 15:43:19 +03:00
# scrobbles
2019-03-12 14:56:53 +03:00
html_scrobbles , _ , _ = module_scrobblelist ( max_ = 15 , shortTimeDesc = True , pictures = True , earlystop = True )
2019-03-18 22:30:28 +03:00
2019-04-10 19:50:56 +03:00
clockp ( " Scrobbles " )
2019-03-18 22:30:28 +03:00
2019-03-04 15:43:19 +03:00
# stats
2019-03-18 22:30:28 +03:00
2019-04-11 13:07:57 +03:00
amount_day = database . get_scrobbles_num ( timerange = today ( ) )
scrobbles_today = " <a href= ' /scrobbles?in=today ' > " + str ( amount_day ) + " </a> "
2019-03-18 22:30:28 +03:00
2019-04-11 13:07:57 +03:00
amount_week = database . get_scrobbles_num ( timerange = thisweek ( ) )
scrobbles_week = " <a href= ' /scrobbles?in=week ' > " + str ( amount_week ) + " </a> "
2019-03-18 22:30:28 +03:00
2019-04-11 13:07:57 +03:00
amount_month = database . get_scrobbles_num ( timerange = thismonth ( ) )
scrobbles_month = " <a href= ' /scrobbles?in=month ' > " + str ( amount_month ) + " </a> "
2019-02-21 02:13:18 +03:00
2019-04-11 13:07:57 +03:00
amount_year = database . get_scrobbles_num ( timerange = thisyear ( ) )
scrobbles_year = " <a href= ' /scrobbles?in=year ' > " + str ( amount_year ) + " </a> "
2019-02-21 02:13:18 +03:00
2019-03-12 18:06:09 +03:00
amount_total = database . get_scrobbles_num ( )
scrobbles_total = " <a href= ' /scrobbles ' > " + str ( amount_total ) + " </a> "
2019-03-18 22:30:28 +03:00
2019-04-10 19:50:56 +03:00
clockp ( " Amounts " )
2019-03-18 22:30:28 +03:00
2019-03-04 15:43:19 +03:00
# pulse
2019-04-11 13:07:57 +03:00
2019-03-18 22:30:28 +03:00
2019-04-10 19:50:56 +03:00
html_pulse_days = module_pulse ( max_ = 7 , since = today ( ) . next ( - 6 ) , step = " day " , trail = 1 )
html_pulse_weeks = module_pulse ( max_ = 12 , since = thisweek ( ) . next ( - 11 ) , step = " week " , trail = 1 )
html_pulse_months = module_pulse ( max_ = 12 , since = thismonth ( ) . next ( - 11 ) , step = " month " , trail = 1 )
html_pulse_years = module_pulse ( max_ = 10 , since = thisyear ( ) . next ( - 9 ) , step = " year " , trail = 1 )
2019-03-18 22:30:28 +03:00
2019-03-10 19:38:33 +03:00
#html_pulse_week = module_pulse(max_=7,since=weekstart,step="day",trail=1)
#html_pulse_month = module_pulse(max_=30,since=[dt.year,dt.month],step="day",trail=1)
#html_pulse_year = module_pulse(max_=12,since=[dt.year],step="month",trail=1)
2019-02-21 02:13:18 +03:00
2019-04-10 19:50:56 +03:00
clockp ( " Pulse " )
2019-03-04 15:43:19 +03:00
2019-03-03 23:22:42 +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
pushresources = [ ]
2019-02-04 15:45:51 +03:00
2019-03-03 23:22:42 +03:00
replace = {
2019-03-03 23:31:48 +03:00
" KEY_TOPARTISTS_TOTAL " : topartists_total , " KEY_TOPARTISTS_YEAR " : topartists_year , " KEY_TOPARTISTS_MONTH " : topartists_month , " KEY_TOPARTISTS_WEEK " : topartists_week ,
" KEY_TOPTRACKS_TOTAL " : toptracks_total , " KEY_TOPTRACKS_YEAR " : toptracks_year , " KEY_TOPTRACKS_MONTH " : toptracks_month , " KEY_TOPTRACKS_WEEK " : toptracks_week ,
2019-04-09 12:56:09 +03:00
" KEY_JS_INIT_RANGES " : js_command ,
2019-04-11 13:07:57 +03:00
" KEY_SCROBBLE_NUM_TODAY " : scrobbles_today , " KEY_SCROBBLE_NUM_WEEK " : scrobbles_week , " KEY_SCROBBLE_NUM_MONTH " : scrobbles_month , " KEY_SCROBBLE_NUM_YEAR " : scrobbles_year , " KEY_SCROBBLE_NUM_TOTAL " : scrobbles_total ,
2019-02-20 20:22:45 +03:00
" KEY_SCROBBLES " : html_scrobbles ,
2019-03-10 19:38:33 +03:00
" KEY_PULSE_MONTHS " : html_pulse_months , " KEY_PULSE_YEARS " : html_pulse_years , " KEY_PULSE_DAYS " : html_pulse_days , " KEY_PULSE_WEEKS " : html_pulse_weeks ,
#"KEY_PULSE_YEAR":html_pulse_year,"KEY_PULSE_MONTH":html_pulse_month,"KEY_PULSE_WEEK":html_pulse_week
2019-02-20 20:22:45 +03:00
}
2019-02-02 18:54:01 +03:00
2019-03-18 22:30:28 +03:00
return ( replace , pushresources )