From 563744c2b9d70b13023879635947ae90465522ff Mon Sep 17 00:00:00 2001 From: Krateng Date: Tue, 2 Apr 2019 11:40:02 +0200 Subject: [PATCH] Added wonky date selector, unused so far --- htmlmodules.py | 22 +++- images/.gitignore | 1 - images/artists/default.jpg | Bin 6986 -> 0 bytes malojatime.py | 135 ++++++++++---------- rules/predefined/krateng_kpopgirlgroups.tsv | 1 + website/css/maloja.css | 10 ++ website/javascript/datechange.js | 43 +++++++ website/topartists.html | 1 + website/topartists.py | 5 +- 9 files changed, 151 insertions(+), 67 deletions(-) delete mode 100644 images/artists/default.jpg create mode 100644 website/javascript/datechange.js diff --git a/htmlmodules.py b/htmlmodules.py index 3694a9f..53364c8 100644 --- a/htmlmodules.py +++ b/htmlmodules.py @@ -289,6 +289,26 @@ def module_filterselection(keys,time=True,delimit=False): keystr = "?" + urllib.parse.urlencode(retainkeys) + # wonky selector for precise date range + +# fromdate = start_of_scrobbling() +# todate = end_of_scrobbling() +# if keys.get("since") is not None: fromdate = keys.get("since") +# if keys.get("to") is not None: todate = keys.get("to") +# if keys.get("in") is not None: fromdate, todate = keys.get("in"), keys.get("in") +# fromdate = time_fix(fromdate) +# todate = time_fix(todate) +# fromdate, todate = time_pad(fromdate,todate,full=True) +# fromdate = [str(e) if e>9 else "0" + str(e) for e in fromdate] +# todate = [str(e) if e>9 else "0" + str(e) for e in todate] +# +# html += "
" +# html += "from " +# html += "to " +# html += "
" + + + html += "
" if keys.get("since") == "today" or keys.get("in") == "today": html += "Today" @@ -333,7 +353,7 @@ def module_filterselection(keys,time=True,delimit=False): html += "Daily" html += " | " - if keys.get("step") == "month": + if keys.get("step") == "month" or keys.get("step") is None: html += "Monthly" else: html += "Monthly" diff --git a/images/.gitignore b/images/.gitignore index fe357fd..cfbc9bc 100644 --- a/images/.gitignore +++ b/images/.gitignore @@ -4,4 +4,3 @@ cached/ *.jpeg *.png *.gif -!default.jpg diff --git a/images/artists/default.jpg b/images/artists/default.jpg deleted file mode 100644 index 0da19b2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^NsiFO`FsV^EHn3ly^OIHTrX2Z%X1t{p%e^5_f3k*Ht7xih#`Xc(#xmca_J5 z8u|N(hpstHSu)@7+26|V3ATXVmG@FR$nsy!-9tlB9lN6whKd zefoa#_{oH1gQ$#FTaQQ`lio->1zo2SXL-^XvMG?vN~JWd3RL>(WUwH%($roJo}8Bf z&vXX&VHudcF=leoV=p7_gjvPSB-|0+j>Dc;jdd+l*LPc~ro9W}MzMW{@@6nd?Uh4P z6gZ9(_kq*}>SMEvao@1*GxJZw5^BOOM-QFuXzsk4lJis(JU%dcV&ksB)A#T1!Ofdy z3FHyuC*W8QRmq??Ze|N_c{tzyGq%-w@eAW{3g3ZH{H$K;!K&(#kis!K<9H<3=sO|4 zQxf&GVm=yh3*ps}8ibI9wuZ5Qyf6qZyy=f*jbg}`gfZW9MD z9eenzyOAU><<=$#+0UmsUQLzmihdscI=|uJvK#yC3S5skl}@JL!6Nw1Q5nk|{1Sn` z5orcpKwd;Htep_S$?K!!v~?EMl$T`a@8^f}%J06JowLi1+a5Q+?v%T!pPrGf?)}Jw zB7~bZARxk9v5>y|5MGfqAp)@WyJGPi5isoL^w^q&Q~^l0{b_o8Y}B5X?qY+UPV17r z2HlSeOcpZDCDtig%qTY3JBkVYNB1iOK3r?0hePr#eLI;QA&>@r1j;e2<>Z$i2dFbY zOw;)X$bGn)<<1F#murTmo+EAeT=~_b8&Z2KjSFr1Ly(64T+xfzS$eNJl*3}G z5qERja)LQ#QnAbZYQLFYZ0C=l z>J#?%stdv%CMSfkWAe_X(Tp#HSnG>~=^!$~mrgX=u-=2>9~{;DH$AzcIx`GyemD!l`%w diff --git a/malojatime.py b/malojatime.py index ebb1257..4238c65 100644 --- a/malojatime.py +++ b/malojatime.py @@ -9,8 +9,16 @@ def register_scrobbletime(timestamp): global FIRST_SCROBBLE if timestamp < FIRST_SCROBBLE: FIRST_SCROBBLE = int(timestamp) - +def start_of_scrobbling(): + global FIRST_SCROBBLE + f = datetime.datetime.utcfromtimestamp(FIRST_SCROBBLE) + return [f.year] + +def end_of_scrobbling(): + global FIRST_SCROBBLE + f = datetime.datetime.now() + return [f.year] @@ -22,15 +30,15 @@ def time_fix(t): tod = datetime.datetime.utcnow() months = ["january","february","march","april","may","june","july","august","september","october","november","december"] weekdays = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"] - + 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 @@ -44,30 +52,30 @@ def time_fix(t): if isinstance(t,str): t = t.split("/") #if isinstance(t,tuple): t = list(t) - + t = [int(p) for p in t] - + return t[:3] -# makes times the same precision level -def time_pad(f,t): +# makes times the same precision level +def time_pad(f,t,full=False): f,t = time_fix(f), time_fix(t) - while len(f) < len(t): + while (len(f) < len(t)) or (full and len(f) < 3): if len(f) == 1: f.append(1) elif len(f) == 2: f.append(1) - while len(f) > len(t): + while (len(f) > len(t)) or (full and len(t) < 3): if len(t) == 1: t.append(12) elif len(t) == 2: t.append(monthrange(*t)[1]) - + return (f,t) - - + + def time_desc(t,short=False): if isinstance(t,int): if short: now = datetime.datetime.now(tz=datetime.timezone.utc) difference = int(now.timestamp() - t) - + if difference < 10: return "just now" if difference < 60: return str(difference) + " seconds ago" difference = int(difference/60) @@ -80,18 +88,18 @@ def time_desc(t,short=False): 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 timeobject.strftime("%d. %B %Y") else: timeobject = datetime.datetime.utcfromtimestamp(t) return timeobject.strftime("%d. %b %Y %I:%M %p") - + else: t = time_fix(t) date = [1970,1,1] date[:len(t)] = t timeobject = datetime.datetime(date[0],date[1],date[2],tzinfo=datetime.timezone.utc) - + nowdate = [1970,1,1] nowobject = datetime.datetime.now(tz=datetime.timezone.utc) nowdate[:len(t)] = [nowobject.year, nowobject.month, nowobject.day][:len(t)] @@ -103,12 +111,12 @@ def time_desc(t,short=False): if diff == 1: return "Yesterday" if diff < 7: return timeobject.strftime("%A") #elif len(t) == 2: - - + + if len(t) == 3: return timeobject.strftime("%d. %B %Y") if len(t) == 2: return timeobject.strftime("%B %Y") if len(t) == 1: return timeobject.strftime("%Y") - + def range_desc(since=None,to=None,within=None,short=False): # the 'short' var we pass down to some of the time_desc calls is a different one than the one here @@ -124,10 +132,10 @@ def range_desc(since=None,to=None,within=None,short=False): sincestr = "" if to is None: tostr = "" - + if isinstance(since,int) and to is None: - sincestr = "since " + time_desc(since) - shortsincestr = sincestr + sincestr = "since " + time_desc(since) + shortsincestr = sincestr elif isinstance(to,int) and since is None: tostr = "up until " + time_desc(to) elif isinstance(since,int) and not isinstance(to,int): @@ -153,50 +161,50 @@ def range_desc(since=None,to=None,within=None,short=False): shortsincestr = time_desc(since,short=True) tostr = "" elif _week(since,to): - + sincestr = "in " + _week(since,to) shortsincestr = _week(since,to) tostr = "" else: fparts = time_desc(since).split(" ") tparts = time_desc(to).split(" ") - + fparts.reverse() tparts.reverse() - + fparts = fparts[len(commonprefix([fparts,tparts])):] - + fparts.reverse() tparts.reverse() - + sincestr = "from " + " ".join(fparts) shortsincestr = " ".join(fparts) tostr = "to " + " ".join(tparts) - + else: if since is not None: sincestr = "since " + time_desc(since) shortsincestr = sincestr if to is not None: tostr = "up until " + time_desc(to) - + if short: return shortsincestr + " " + tostr else: return sincestr + " " + tostr - - - - - + + + + + def time_stamps(since=None,to=None,within=None): - + if within is not None: since = within to = within - - - - + + + + if (since==None): stamp1 = FIRST_SCROBBLE else: since = time_fix(since) @@ -211,42 +219,42 @@ def time_stamps(since=None,to=None,within=None): date = [1970,1,1] date[:len(to)] = to stamp2 = int(datetime.datetime(date[0],date[1],date[2],tzinfo=datetime.timezone.utc).timestamp()) - - + + return (stamp1,stamp2) - - - - + + + + def delimit_desc(step="month",stepn=1,trail=1): txt = "" if stepn is not 1: txt += _num(stepn) + "-" txt += {"year":"Yearly","month":"Monthly","day":"Daily"}[step.lower()] #if trail is not 1: txt += " " + _num(trail) + "-Trailing" if trail is not 1: txt += " Trailing" #we don't need all the info in the title - + return txt - - + + def _week(since,to): if len(since) != 3 or len(to) != 3: return False dt_since, dt_to = datetime.datetime(*since,tzinfo=datetime.timezone.utc), datetime.datetime(*to,tzinfo=datetime.timezone.utc) if (dt_to - dt_since).days != 6: return False if dt_since.weekday() != 6: return False - + c = dt_to.isocalendar()[:2] return str("Week " + str(c[1]) + " " + str(c[0])) - + def _num(i): names = ["Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve"] if i < len(names): return names[i] else: return str(i) - - - - - - + + + + + + def ranges(since=None,to=None,within=None,step="month",stepn=1,trail=1,max_=None): (firstincluded,lastincluded) = time_stamps(since=since,to=to,within=within) @@ -256,7 +264,7 @@ def ranges(since=None,to=None,within=None,step="month",stepn=1,trail=1,max_=None d_start = _get_next(d_start,step,stepn) # first range should end right after the first active scrobbling week / month / whatever relevant step d_start = _get_next(d_start,step,stepn * trail * -1) # go one range back to begin - + i = 0 d_current = d_start while not _is_past(d_current,d_end) and (max_ is None or i < max_): @@ -282,7 +290,7 @@ def _get_start_of(timestamp,unit): d = datetime.timedelta(days=change) newdate = date - d return [newdate.year,newdate.month,newdate.day] - + def _get_next(time,unit="auto",step=1): result = time[:] if unit == "auto": @@ -313,7 +321,7 @@ def _get_next(time,unit="auto",step=1): #eugh elif unit == "week": return _get_next(time,"day",step * 7) - + # like _get_next(), but gets the last INCLUDED day / month whatever def _get_end(time,unit="auto",step=1): if step == 1: @@ -324,9 +332,9 @@ def _get_end(time,unit="auto",step=1): exc = _get_next(time,unit,step) inc = _get_next(exc,"auto",-1) return inc - - - + + + def _is_past(date,limit): date_, limit_ = date[:], limit[:] while len(date_) != 3: date_.append(1) @@ -336,4 +344,3 @@ def _is_past(date,limit): if not date_[1] == limit_[1]: return date_[1] > limit_[1] return (date_[2] > limit_[2]) - diff --git a/rules/predefined/krateng_kpopgirlgroups.tsv b/rules/predefined/krateng_kpopgirlgroups.tsv index 43451bb..4a09812 100644 --- a/rules/predefined/krateng_kpopgirlgroups.tsv +++ b/rules/predefined/krateng_kpopgirlgroups.tsv @@ -84,6 +84,7 @@ replacetitle FEMALE PRESIDENT(여자 대통령) Female President # Mamamoo replaceartist Hwa Sa Hwasa replaceartist MAMAMOO Mamamoo +replacetitle Egotistic(너나 해) Egotistic # Hello Venus replaceartist Hello/Venus Hello Venus diff --git a/website/css/maloja.css b/website/css/maloja.css index 21fc52e..9632f35 100644 --- a/website/css/maloja.css +++ b/website/css/maloja.css @@ -26,6 +26,16 @@ a:hover { } +input[type="date"] { + background-color:inherit; + color:inherit; + outline: none; + border:0px; + font-family: inherit; + font-size: inherit; + +} + /** Header (unused) **/ diff --git a/website/javascript/datechange.js b/website/javascript/datechange.js new file mode 100644 index 0000000..46693e2 --- /dev/null +++ b/website/javascript/datechange.js @@ -0,0 +1,43 @@ +function datechange() { + + since = document.getElementById("dateselect_from").value; + to = document.getElementById("dateselect_to").value; + + since = since.split("-").join("/") + to = to.split("-").join("/") + + //url = window.location.href + //var url = document.createElement("a") + //url.href = window.location.href + //console.log(url.search) + + keys = window.location.search.substring(1).split("&") + + + var keydict = {}; + for (var i=0;i Maloja - Top Artists + diff --git a/website/topartists.py b/website/topartists.py index a090dcc..1e7010d 100644 --- a/website/topartists.py +++ b/website/topartists.py @@ -26,6 +26,9 @@ def instructions(keys): pushresources = [{"file":imgurl,"type":"image"}] if imgurl.startswith("/") else [] - replace = {"KEY_TOPARTIST_IMAGEURL":imgurl,"KEY_ARTISTLIST":html_charts,"KEY_RANGE":limitstring,"KEY_FILTERSELECTOR":html_filterselector} + replace = {"KEY_TOPARTIST_IMAGEURL":imgurl, + "KEY_ARTISTLIST":html_charts, + "KEY_RANGE":limitstring, + "KEY_FILTERSELECTOR":html_filterselector} return (replace,pushresources)