diff --git a/database.py b/database.py
index 1738ab1..062ad7d 100644
--- a/database.py
+++ b/database.py
@@ -6,6 +6,7 @@ import os
import datetime
from cleanup import *
from utilities import *
+from malojatime import *
import sys
dbserver = Bottle()
@@ -67,6 +68,7 @@ def createScrobble(artists,title,time):
i = getTrackID(artists,title)
obj = (i,time,False)
SCROBBLES.append(obj)
+ register_scrobbletime(time)
def readScrobble(artists,title,time):
@@ -76,6 +78,7 @@ def readScrobble(artists,title,time):
i = getTrackID(artists,title)
obj = (i,time,True)
SCROBBLES.append(obj)
+ register_scrobbletime(time)
def getArtistID(name):
@@ -314,7 +317,7 @@ def get_pulse_external():
def get_pulse(step="month",stepn=1,trail=1,**keys):
- (ts_start,ts_end) = getTimestamps(**{k:keys[k] for k in keys if k in ["since","to","within"]})
+ (ts_start,ts_end) = time_stamps(**{k:keys[k] for k in keys if k in ["since","to","within"]})
d_start = getStartOf(ts_start,step)
d_end = getStartOf(ts_end,step)
d_start = getNext(d_start,step,stepn) # first range should end right after the first active scrobbling week / month / whatever relevant step
@@ -330,7 +333,7 @@ def get_pulse(step="month",stepn=1,trail=1,**keys):
res = len(db_query(since=d_current,to=d_current_end,**{k:keys[k] for k in keys if k in ["artists","artist","track","title","associated"]}))
results.append({"from":d_current,"to":d_current_end,"scrobbles":res})
d_current = getNext(d_current,step,stepn)
- if isPast(d_current_end,d_end):
+ if isPast(d_current,d_end):
break
return results
@@ -358,7 +361,7 @@ def get_top_artists_external():
def get_top_artists(step="month",stepn=1,trail=3,**keys):
- (ts_start,ts_end) = getTimestamps(**{k:keys[k] for k in keys if k in ["since","to","within"]})
+ (ts_start,ts_end) = time_stamps(**{k:keys[k] for k in keys if k in ["since","to","within"]})
d_start = getStartOf(ts_start,step)
d_end = getStartOf(ts_end,step)
d_start = getNext(d_start,step,stepn) # first range should end right after the first active scrobbling week / month / whatever relevant step
@@ -375,7 +378,7 @@ def get_top_artists(step="month",stepn=1,trail=3,**keys):
except:
results.append({"from":d_current,"to":d_current_end,"artist":None,"scrobbles":0})
d_current = getNext(d_current,step,stepn)
- if isPast(d_current_end,d_end):
+ if isPast(d_current,d_end):
break
return results
@@ -404,7 +407,7 @@ def get_top_tracks_external():
def get_top_tracks(step="month",stepn=1,trail=3,**keys):
- (ts_start,ts_end) = getTimestamps(**{k:keys[k] for k in keys if k in ["since","to","within"]})
+ (ts_start,ts_end) = time_stamps(**{k:keys[k] for k in keys if k in ["since","to","within"]})
d_start = getStartOf(ts_start,step)
d_end = getStartOf(ts_end,step)
d_start = getNext(d_start,step,stepn) # first range should end right after the first active scrobbling week / month / whatever relevant step
@@ -422,7 +425,7 @@ def get_top_tracks(step="month",stepn=1,trail=3,**keys):
except:
results.append({"from":d_current,"to":d_current_end,"track":None,"scrobbles":0})
d_current = getNext(d_current,step,stepn)
- if isPast(d_current_end,d_end):
+ if isPast(d_current,d_end):
break
return results
@@ -854,7 +857,7 @@ def db_query(artist=None,artists=None,title=None,track=None,since=None,to=None,w
# print(within)
# print(associated)
- (since, to) = getTimestamps(since,to,within)
+ (since, to) = time_stamps(since,to,within)
# this is not meant as a search function. we *can* query the db with a string, but it only works if it matches exactly
# if a title is specified, we assume that a specific track (with the exact artist combination) is requested
@@ -898,7 +901,7 @@ def db_query(artist=None,artists=None,title=None,track=None,since=None,to=None,w
# Queries that... well... aggregate
def db_aggregate(by=None,since=None,to=None,within=None,artist=None):
- (since, to) = getTimestamps(since,to,within)
+ (since, to) = time_stamps(since,to,within)
if isinstance(artist, str):
artist = ARTISTS.index(artist)
@@ -959,71 +962,72 @@ def db_search(query,type=None):
# Takes user inputs like YYYY/MM and returns the timestamps. Returns timestamp if timestamp was already given.
# to dates are interpreted differently (from 2010 and to 2010 both include all of 2010)
-def getTimestamps(since=None,to=None,within=None):
-
- f,t,i = since,to,within
-
- if i is not None:
- f = i
- t = i
-
- if isinstance(f, str) and f.lower() == "today":
- tod = datetime.datetime.utcnow()
- f = [tod.year,tod.month,tod.day]
- if isinstance(t, str) and t.lower() == "today":
- tod = datetime.datetime.utcnow()
- t = [tod.year,tod.month,tod.day]
-
-
- if isinstance(f, str) and f.lower() == "month":
- tod = datetime.datetime.utcnow()
- f = [tod.year,tod.month]
- if isinstance(t, str) and t.lower() == "month":
- tod = datetime.datetime.utcnow()
- t = [tod.year,tod.month]
-
-
- if isinstance(f, str) and f.lower() == "year":
- tod = datetime.datetime.utcnow()
- f = [tod.year]
- if isinstance(t, str) and t.lower() == "year":
- tod = datetime.datetime.utcnow()
- t = [tod.year]
-
-
- if isinstance(f, str):
- f = [int(x) for x in f.split("/")]
-
- if isinstance(t, str):
- t = [int(x) for x in t.split("/")]
-
-
- # this step is done if either the input is a list or the first step was done (which creates a list)
- if isinstance(f, list):
- date = [1970,1,1]
- date[:len(f)] = f
- #while len(f) < 3: f.append(1) # padding month and day
- f = date
- #f = int(datetime.datetime(date[0],date[1],date[2],date[3],date[4],tzinfo=datetime.timezone.utc).timestamp())
- f = int(datetime.datetime(f[0],f[1],f[2],tzinfo=datetime.timezone.utc).timestamp())
-
- if isinstance(t, list):
- t = getNext(t)
- #while len(t) < 3: t.append(1)
- date = [1970,1,1]
- date[:len(t)] = t
- t = date
- #t = int(datetime.datetime(date[0],date[1],date[2],date[3],date[4],tzinfo=datetime.timezone.utc).timestamp())
- t = int(datetime.datetime(t[0],t[1],t[2],tzinfo=datetime.timezone.utc).timestamp())
-
- if (f==None):
- f = min(timestamps)
- if (t==None):
- t = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()
-
- return (f,t)
-
-
+# NOW DONE IN THE MALOJATIME MODULE
+#def getTimestamps(since=None,to=None,within=None):
+#
+# f,t,i = since,to,within
+#
+# if i is not None:
+# f = i
+# t = i
+#
+# if isinstance(f, str) and f.lower() == "today":
+# tod = datetime.datetime.utcnow()
+# f = [tod.year,tod.month,tod.day]
+# if isinstance(t, str) and t.lower() == "today":
+# tod = datetime.datetime.utcnow()
+# t = [tod.year,tod.month,tod.day]
+#
+#
+# if isinstance(f, str) and f.lower() == "month":
+# tod = datetime.datetime.utcnow()
+# f = [tod.year,tod.month]
+# if isinstance(t, str) and t.lower() == "month":
+# tod = datetime.datetime.utcnow()
+# t = [tod.year,tod.month]
+#
+#
+# if isinstance(f, str) and f.lower() == "year":
+# tod = datetime.datetime.utcnow()
+# f = [tod.year]
+# if isinstance(t, str) and t.lower() == "year":
+# tod = datetime.datetime.utcnow()
+# t = [tod.year]
+#
+#
+# if isinstance(f, str):
+# f = [int(x) for x in f.split("/")]
+#
+# if isinstance(t, str):
+# t = [int(x) for x in t.split("/")]
+#
+#
+# # this step is done if either the input is a list or the first step was done (which creates a list)
+# if isinstance(f, list):
+# date = [1970,1,1]
+# date[:len(f)] = f
+# #while len(f) < 3: f.append(1) # padding month and day
+# f = date
+# #f = int(datetime.datetime(date[0],date[1],date[2],date[3],date[4],tzinfo=datetime.timezone.utc).timestamp())
+# f = int(datetime.datetime(f[0],f[1],f[2],tzinfo=datetime.timezone.utc).timestamp())
+#
+# if isinstance(t, list):
+# t = getNext(t)
+# #while len(t) < 3: t.append(1)
+# date = [1970,1,1]
+# date[:len(t)] = t
+# t = date
+# #t = int(datetime.datetime(date[0],date[1],date[2],date[3],date[4],tzinfo=datetime.timezone.utc).timestamp())
+# t = int(datetime.datetime(t[0],t[1],t[2],tzinfo=datetime.timezone.utc).timestamp())
+#
+# if (f==None):
+# f = min(timestamps)
+# if (t==None):
+# t = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).timestamp()
+#
+# return (f,t)
+#
+#
diff --git a/htmlgenerators.py b/htmlgenerators.py
index 314957e..97d492c 100644
--- a/htmlgenerators.py
+++ b/htmlgenerators.py
@@ -61,52 +61,52 @@ def removeIdentical(*dicts):
return new
-def getTimeDesc(timestamp,short=False):
- tim = datetime.datetime.utcfromtimestamp(timestamp)
- if short:
- now = datetime.datetime.now(tz=datetime.timezone.utc)
- difference = int(now.timestamp() - timestamp)
+#def getTimeDesc(timestamp,short=False):
+# tim = datetime.datetime.utcfromtimestamp(timestamp)
+# if short:
+# now = datetime.datetime.now(tz=datetime.timezone.utc)
+# difference = int(now.timestamp() - timestamp)
+#
+# if difference < 10: return "just now"
+# if difference < 60: return str(difference) + " seconds ago"
+# difference = int(difference/60)
+# if difference < 60: return str(difference) + " minutes ago" if difference>1 else str(difference) + " minute ago"
+# difference = int(difference/60)
+# if difference < 24: return str(difference) + " hours ago" if difference>1 else str(difference) + " hour ago"
+# difference = int(difference/24)
+# if difference < 5: return tim.strftime("%A")
+# if difference < 31: return str(difference) + " days ago" if difference>1 else str(difference) + " day ago"
+# #if difference < 300 and tim.year == now.year: return tim.strftime("%B")
+# #if difference < 300: return tim.strftime("%B %Y")
+#
+# return tim.strftime("%d. %B %Y")
+# else:
+# return tim.strftime("%d. %b %Y %I:%M %p")
- if difference < 10: return "just now"
- if difference < 60: return str(difference) + " seconds ago"
- difference = int(difference/60)
- if difference < 60: return str(difference) + " minutes ago" if difference>1 else str(difference) + " minute ago"
- difference = int(difference/60)
- if difference < 24: return str(difference) + " hours ago" if difference>1 else str(difference) + " hour ago"
- difference = int(difference/24)
- if difference < 5: return tim.strftime("%A")
- if difference < 31: return str(difference) + " days ago" if difference>1 else str(difference) + " day ago"
- #if difference < 300 and tim.year == now.year: return tim.strftime("%B")
- #if difference < 300: return tim.strftime("%B %Y")
-
- return tim.strftime("%d. %B %Y")
- else:
- return tim.strftime("%d. %b %Y %I:%M %p")
-
-def getRangeDesc(timeA,timeB,inclusiveB=True):
- # string to list
- if isinstance(timeA,str): timeA = timeA.split("/")
- if isinstance(timeB,str): timeB = timeB.split("/")
-
- # if lists, we have it potentially much easier:
- if isinstance(timeA,list) and isinstance(timeB,list):
- if timeA == timeB:
- date = [1970,1,1]
- date[:len(timeA)] = timeA
- dto = datetime.datetime(date[0],date[1],date[2],tzinfo=datetime.timezone.utc)
- if len(timeA) == 3:
- return dto.strftime("%d. %b %Y")
- if len(timeA) == 2:
- return dto.strftime("%B %Y")
- if len(timeA) == 1:
- return dto.strftime("%Y")
-
- from database import getTimestamps
-
- (timeA, timeB) = getTimestamps(since=timeA, to=timeB)
-
-
- return getTimeDesc(timeA) + " to " + getTimeDesc(timeB)
+#def getRangeDesc(since=None,to=None,inclusiveB=True):
+# # string to list
+# if isinstance(timeA,str): timeA = timeA.split("/")
+# if isinstance(timeB,str): timeB = timeB.split("/")
+#
+# # if lists, we have it potentially much easier:
+# if isinstance(timeA,list) and isinstance(timeB,list):
+# if timeA == timeB:
+# date = [1970,1,1]
+# date[:len(timeA)] = timeA
+# dto = datetime.datetime(date[0],date[1],date[2],tzinfo=datetime.timezone.utc)
+# if len(timeA) == 3:
+# return dto.strftime("%d. %b %Y")
+# if len(timeA) == 2:
+# return dto.strftime("%B %Y")
+# if len(timeA) == 1:
+# return dto.strftime("%Y")
+#
+#
+#
+# (timeA, timeB) = getTimestamps(since=timeA, to=timeB)
+#
+#
+# return getTimeDesc(timeA) + " to " + getTimeDesc(timeB)
@@ -191,10 +191,10 @@ def pickKeys(d,*keys):
return finald
# removes all duplicate keys, except artists when a title is specified
-def clean(d):
- if isinstance(d,dict):
- return
- else:
- for k in d:
- if (k != "artist") or "title" not in d:
- d[k] = d.pop(k)
+#def clean(d):
+# if isinstance(d,dict):
+# return
+# else:
+# for k in d:
+# if (k != "artist") or "title" not in d:
+# d[k] = d.pop(k)
diff --git a/htmlmodules.py b/htmlmodules.py
index 0fc4517..e62a75a 100644
--- a/htmlmodules.py
+++ b/htmlmodules.py
@@ -1,6 +1,7 @@
from htmlgenerators import *
import database
from utilities import getArtistsInfo, getTracksInfo
+from malojatime import *
import urllib
@@ -26,7 +27,7 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
#scrobbleimages = [e.get("image") for e in getTracksInfo(scrobbleswithpictures)] #will still work with scrobble objects as they are a technically a subset of track objects
scrobbleimages = ["/image?title=" + urllib.parse.quote(t["title"]) + "&" + "&".join(["artist=" + urllib.parse.quote(a) for a in t["artists"]]) for t in scrobbleswithpictures]
- representative = scrobbles[0] if scrobbles is not [] else None
+ representative = scrobbles[0] if len(scrobbles) is not 0 else None
# build list
i = 0
@@ -34,7 +35,7 @@ def module_scrobblelist(max_=None,pictures=False,shortTimeDesc=False,**kwargs):
for s in scrobbles:
html += "
"
@@ -58,6 +59,13 @@ def module_pulse(max_=None,**kwargs):
ranges = database.get_pulse(**kwargs_time,**kwargs_filter)
+ if max_ is not None: ranges = ranges[:max_]
+
+ # if time range not explicitly specified, only show from first appearance
+# if "since" not in kwargs:
+# while ranges[0]["scrobbles"] == 0:
+# del ranges[0]
+
maxbar = max([t["scrobbles"] for t in ranges])
maxbar = max(maxbar,1)
@@ -67,7 +75,7 @@ def module_pulse(max_=None,**kwargs):
fromstr = "/".join([str(e) for e in t["from"]])
tostr = "/".join([str(e) for e in t["to"]])
html += "