mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Additional time options
This commit is contained in:
parent
ca90adc842
commit
58aae2643c
@ -18,25 +18,29 @@ def register_scrobbletime(timestamp):
|
||||
def time_fix(t):
|
||||
|
||||
|
||||
if isinstance(t, str) and t.lower() == "today":
|
||||
if isinstance(t, str):
|
||||
tod = datetime.datetime.utcnow()
|
||||
t = [tod.year,tod.month,tod.day]
|
||||
if isinstance(t, str) and t.lower() == "month":
|
||||
tod = datetime.datetime.utcnow()
|
||||
t = [tod.year,tod.month]
|
||||
if isinstance(t, str) and t.lower() == "year":
|
||||
tod = datetime.datetime.utcnow()
|
||||
t = [tod.year]
|
||||
|
||||
# SPECIAL CASE: Weeks only work for SINCE, but let's hope nobody finds out
|
||||
if isinstance(t, str) and t.lower() == "week":
|
||||
tod = datetime.datetime.utcnow()
|
||||
change = (tod.weekday() + 1) % 7
|
||||
d = datetime.timedelta(days=change)
|
||||
newdate = tod - d
|
||||
months = ["january","february","march","april","may","june","july","august","september","october","november","december"]
|
||||
weekdays = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"]
|
||||
|
||||
t = [newdate.year,newdate.month,newdate.day]
|
||||
if t.lower() in ["today","day"]:
|
||||
t = [tod.year,tod.month,tod.day]
|
||||
elif t.lower() == "month":
|
||||
t = [tod.year,tod.month]
|
||||
elif t.lower() == "year":
|
||||
t = [tod.year]
|
||||
|
||||
|
||||
elif t.lower() in months:
|
||||
#diff = (tod.month - months.index(t.lower()) - 1)
|
||||
month = months.index(t.lower()) + 1
|
||||
t = [tod.year,month]
|
||||
if month > tod.month: t[0] -= 1
|
||||
elif t.lower() in weekdays:
|
||||
weekday = weekdays.index(t.lower())
|
||||
diff = (tod.isoweekday() - weekday) % 7
|
||||
dt = tod - datetime.timedelta(diff)
|
||||
t = [dt.year,dt.month,dt.day]
|
||||
|
||||
if isinstance(t,str): t = t.split("/")
|
||||
#if isinstance(t,tuple): t = list(t)
|
||||
|
@ -6,43 +6,35 @@ from htmlmodules import module_scrobblelist, module_pulse, module_artistcharts_t
|
||||
|
||||
|
||||
def instructions(keys):
|
||||
from utilities import getArtistsInfo, getTracksInfo
|
||||
from htmlgenerators import artistLink, trackLink
|
||||
|
||||
# max_show = 14
|
||||
# posrange = ["#" + str(i) for i in range(1,max_show+1)]
|
||||
|
||||
# get chart data
|
||||
|
||||
# get start of week
|
||||
tod = datetime.utcnow()
|
||||
change = (tod.weekday() + 1) % 7
|
||||
d = timedelta(days=change)
|
||||
newdate = tod - d
|
||||
weekstart = [newdate.year,newdate.month,newdate.day]
|
||||
|
||||
# artists
|
||||
# charts = database.get_charts_artists()[:max_show]
|
||||
# artisttitles = [c["artist"] for c in charts]
|
||||
# artistimages = ["/image?artist=" + urllib.parse.quote(a) for a in artisttitles]
|
||||
# artistlinks = [artistLink(a) for a in artisttitles]
|
||||
|
||||
topartists_total = module_artistcharts_tiles()
|
||||
topartists_year = module_artistcharts_tiles(since="year")
|
||||
topartists_month = module_artistcharts_tiles(since="month")
|
||||
topartists_week = module_artistcharts_tiles(since="week")
|
||||
topartists_week = module_artistcharts_tiles(since=weekstart)
|
||||
|
||||
|
||||
# tracks
|
||||
# charts = database.get_charts_tracks()[:max_show]
|
||||
# trackobjects = [t["track"] for t in charts]
|
||||
# tracktitles = [t["title"] for t in trackobjects]
|
||||
# trackimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]]) for t in trackobjects]
|
||||
# tracklinks = [trackLink(t) for t in trackobjects]
|
||||
|
||||
toptracks_total = module_trackcharts_tiles()
|
||||
toptracks_year = module_trackcharts_tiles(since="year")
|
||||
toptracks_month = module_trackcharts_tiles(since="month")
|
||||
toptracks_week = module_trackcharts_tiles(since="week")
|
||||
toptracks_week = module_trackcharts_tiles(since=weekstart)
|
||||
|
||||
# get scrobbles
|
||||
|
||||
# scrobbles
|
||||
html_scrobbles, _, _ = module_scrobblelist(max_=15,shortTimeDesc=True,pictures=True)
|
||||
|
||||
|
||||
# get stats
|
||||
# stats
|
||||
amount = database.get_scrobbles_num(since="today")
|
||||
scrobbles_today = "<a href='/scrobbles?since=today'>" + str(amount) + "</a>"
|
||||
|
||||
@ -56,7 +48,7 @@ def instructions(keys):
|
||||
scrobbles_total = "<a href='/scrobbles'>" + str(amount) + "</a>"
|
||||
|
||||
|
||||
# get pulse
|
||||
# pulse
|
||||
dt = datetime.utcnow()
|
||||
first_month = [dt.year-1,dt.month+1]
|
||||
dt_firstweek = dt - timedelta(11*7) - timedelta((6-dt.weekday()))
|
||||
@ -64,20 +56,15 @@ def instructions(keys):
|
||||
dt_firstday = dt - timedelta(6)
|
||||
first_day = [dt_firstday.year,dt_firstday.month,dt_firstday.day]
|
||||
first_year = [dt.year - 9]
|
||||
|
||||
if first_month[1] > 12: first_month = [first_month[0]+1,first_month[1]-12]
|
||||
#while first_week[2]
|
||||
|
||||
|
||||
#first_month = "/".join([str(e) for e in first_month])
|
||||
# this is literally the ugliest piece of code i have written in my entire feckin life
|
||||
# good lord
|
||||
|
||||
html_pulse_days = module_pulse(max_=7,since=first_day,step="day",trail=1)
|
||||
html_pulse_weeks = module_pulse(max_=12,since=first_week,step="week",trail=1)
|
||||
html_pulse_months = module_pulse(max_=12,since=first_month,step="month",trail=1)
|
||||
html_pulse_years = module_pulse(max_=10,since=first_year,step="year",trail=1)
|
||||
|
||||
|
||||
|
||||
#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 = []
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user