1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added pulse on main page

This commit is contained in:
Krateng 2019-02-18 17:22:44 +01:00
parent 28f35aa12a
commit f29c5ca8b9
3 changed files with 109 additions and 64 deletions

4
maloja
View File

@ -174,12 +174,14 @@ def update():
os.system("wget " + SOURCE_URL) os.system("wget " + SOURCE_URL)
with zipfile.ZipFile("master.zip","r") as z: with zipfile.ZipFile("./master.zip","r") as z:
for f in z.namelist(): for f in z.namelist():
#print("extracting " + f) #print("extracting " + f)
z.extract(f) z.extract(f)
os.remove("./master.zip")
distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2) distutils.dir_util.copy_tree("./maloja-master/","./",verbose=2)
shutil.rmtree("./maloja-master") shutil.rmtree("./maloja-master")

View File

@ -207,65 +207,85 @@
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='artists'>KEY_SCROBBLE_ARTISTS</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='title'>KEY_SCROBBLE_TITLE</td>
</tr> </tr>
</table>
<br/>
<table class='list'>
<h1><a href="/pulse?step=month&trail=1">Pulse</a></h1>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
<tr> <tr>
<td class='time'>KEY_SCROBBLE_TIME</td> <td>KEY_PULSE_TERM_FROM</td>
<td class='icon'><div style="background-image:url('KEY_SCROBBLE_IMAGE')"></div></td> <td>KEY_PULSE_TERM_TO</td>
<td class='artists'>KEY_SCROBBLE_ARTISTS</td> <td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='title'>KEY_SCROBBLE_TITLE</td> <td class='bar'>KEY_PULSE_BAR</td>
</tr>
<tr>
<td>KEY_PULSE_TERM_FROM</td>
<td>KEY_PULSE_TERM_TO</td>
<td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='bar'>KEY_PULSE_BAR</td>
</tr>
<tr>
<td>KEY_PULSE_TERM_FROM</td>
<td>KEY_PULSE_TERM_TO</td>
<td class='amount'>KEY_PULSE_AMOUNT</td>
<td class='bar'>KEY_PULSE_BAR</td>
</tr> </tr>
</table> </table>
</div> </div>

View File

@ -1,6 +1,7 @@
import urllib import urllib
import json import json
from threading import Thread from threading import Thread
from datetime import datetime
#import database #import database
@ -15,7 +16,7 @@ def getpictures(ls,result,tracks=False):
def instructions(keys,dbport): def instructions(keys,dbport):
from utilities import getArtistsInfo, getTracksInfo from utilities import getArtistsInfo, getTracksInfo
from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, keysToUrl, pickKeys, clean, getTimeDesc from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, scrobblesLink, keysToUrl, pickKeys, clean, getTimeDesc
max_show = 15 max_show = 15
posrange = ["#" + str(i) for i in range(1,max_show)] posrange = ["#" + str(i) for i in range(1,max_show)]
@ -92,6 +93,27 @@ def instructions(keys,dbport):
scrobbles_total = "<a href='/scrobbles'>" + str(stats["amount"]) + "</a>" scrobbles_total = "<a href='/scrobbles'>" + str(stats["amount"]) + "</a>"
# get pulse
dt = datetime.utcnow()
dtl = [dt.year-1,dt.month+1]
if dtl[1] > 12: dtl = [dtl[0]+1,dtl[1]-12]
dts = "/".join([str(e) for e in dtl])
# this is literally the ugliest piece of code i have written in my entire feckin life
# good lord
response = urllib.request.urlopen("http://[::1]:" + str(dbport) + "/pulse?step=month&trail=1&since=" + dts)
db_data = json.loads(response.read())
terms = db_data["list"]
maxbar = max([t["scrobbles"] for t in terms])
pulse_fromdates = ["/".join([str(e) for e in t["from"]]) for t in terms]
pulse_todates = ["/".join([str(e) for e in t["to"]]) for t in terms]
pulse_amounts = [scrobblesLink({"since":"/".join([str(e) for e in t["from"]]),"to":"/".join([str(e) for e in t["to"]])},amount=t["scrobbles"]) for t in terms]
pulse_bars = [scrobblesLink({"since":"/".join([str(e) for e in t["from"]]),"to":"/".join([str(e) for e in t["to"]])},percent=t["scrobbles"]*100/maxbar) for t in terms]
t1.join() t1.join()
t2.join() t2.join()
@ -103,7 +125,8 @@ def instructions(keys,dbport):
replace = {"KEY_ARTISTIMAGE":artistimages,"KEY_ARTISTNAME":artisttitles,"KEY_ARTISTLINK":artistlinks,"KEY_POSITION_ARTIST":posrange, replace = {"KEY_ARTISTIMAGE":artistimages,"KEY_ARTISTNAME":artisttitles,"KEY_ARTISTLINK":artistlinks,"KEY_POSITION_ARTIST":posrange,
"KEY_TRACKIMAGE":trackimages,"KEY_TRACKNAME":tracktitles,"KEY_TRACKLINK":tracklinks,"KEY_POSITION_TRACK":posrange, "KEY_TRACKIMAGE":trackimages,"KEY_TRACKNAME":tracktitles,"KEY_TRACKLINK":tracklinks,"KEY_POSITION_TRACK":posrange,
"KEY_SCROBBLES_TODAY":scrobbles_today,"KEY_SCROBBLES_MONTH":scrobbles_month,"KEY_SCROBBLES_YEAR":scrobbles_year,"KEY_SCROBBLES_TOTAL":scrobbles_total, "KEY_SCROBBLES_TODAY":scrobbles_today,"KEY_SCROBBLES_MONTH":scrobbles_month,"KEY_SCROBBLES_YEAR":scrobbles_year,"KEY_SCROBBLES_TOTAL":scrobbles_total,
"KEY_SCROBBLE_TIME":scrobbletimes,"KEY_SCROBBLE_ARTISTS":scrobbleartists,"KEY_SCROBBLE_TITLE":scrobbletracklinks,"KEY_SCROBBLE_IMAGE":scrobbleimages} "KEY_SCROBBLE_TIME":scrobbletimes,"KEY_SCROBBLE_ARTISTS":scrobbleartists,"KEY_SCROBBLE_TITLE":scrobbletracklinks,"KEY_SCROBBLE_IMAGE":scrobbleimages,
"KEY_PULSE_TERM_FROM":pulse_fromdates,"KEY_PULSE_TERM_TO":pulse_todates,"KEY_PULSE_AMOUNT":pulse_amounts,"KEY_PULSE_BAR":pulse_bars}
return (replace,pushresources) return (replace,pushresources)