From 562c796a923d48ea3f816a3200178be369b3edd9 Mon Sep 17 00:00:00 2001 From: Krateng Date: Sat, 2 Feb 2019 16:54:01 +0100 Subject: [PATCH] Rudimentary start page --- database.py | 5 ++- server.py | 4 +- website/maloja.css | 94 ++++++++++++++++++++++++++++++++++++++++++++-- website/start.html | 52 +++++++++++++++++++++++++ website/start.py | 34 +++++++++++++++++ 5 files changed, 182 insertions(+), 7 deletions(-) create mode 100644 website/start.html create mode 100644 website/start.py diff --git a/database.py b/database.py index 2d5e4a0..3f49998 100644 --- a/database.py +++ b/database.py @@ -410,8 +410,9 @@ def post_scrobble(): createScrobble(artists,title,time) - if (time - lastsync) > 3600: - sync() + #if (time - lastsync) > 3600: + # sync() + sync() #let's just always sync, not like one filesystem access every three minutes is a problem and it avoids lost tracks when we lose power return "" diff --git a/server.py b/server.py index 3ecc19b..f3fe41f 100755 --- a/server.py +++ b/server.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict +from bottle import Bottle, route, get, post, error, run, template, static_file, request, response, FormsDict, redirect, template from importlib.machinery import SourceFileLoader from htmlgenerators import removeIdentical from utilities import * @@ -23,7 +23,7 @@ webserver = Bottle() @webserver.route("") @webserver.route("/") def mainpage(): - return static_file("main.html",root="") + return static_html("start") # this is the fallback option. If you run this service behind a reverse proxy, it is recommended to rewrite /db/ requests to the port of the db server diff --git a/website/maloja.css b/website/maloja.css index 2b63497..47f34b8 100644 --- a/website/maloja.css +++ b/website/maloja.css @@ -16,6 +16,13 @@ a:hover { text-decoration:underline; } +/* +** +** +** TOP INFO TABLE +** +** +*/ table.top_info td.image { padding:20px; @@ -48,11 +55,19 @@ p.desc a { background-image:url("https://www.last.fm/static/images/lastfm_avatar_twitter.66cd2c48ce03.png"); } + + /* -table.top_info td.text .stats { - color:grey; -} +** +** +** SPECIAL TEXT BITS +** +** */ + + + + .stats { color:grey; } @@ -69,6 +84,20 @@ a { cursor:pointer; } + + +/* +** +** +** LISTS +** +** +*/ + + + + + table.list { border-collapse:collapse; } @@ -177,3 +206,62 @@ td.button.important div { background-color:red; color:white; } + + + + + + +/* +** +** +** IMAGE TILES +** +** +*/ + + + + + + + +table.tiles_top td { + padding:0px; + border:0px; +} + +table.tiles_top, table.tiles_sub { + border-collapse: collapse; +} + + + +table.tiles_top>tbody>tr>td { + height:300px; + width:300px; +} + +table.tiles_sub { + height:100%; + width:100%; +} + + +table.tiles_top td div { + background-size:cover; + background-position:center; + height:100%; + width:100%; +} + +table.tiles_2x2 td { + height:50%; + width:50%; + font-size:90% +} +table.tiles_3x3 td { + height:33.333%; + width:33.333%; + font-size:70% +} diff --git a/website/start.html b/website/start.html new file mode 100644 index 0000000..bf424ff --- /dev/null +++ b/website/start.html @@ -0,0 +1,52 @@ + + + + + + Maloja + + + + + +

Top Artists

+ + + + + + +
KEY_POSITION KEY_ARTISTLINK
+ + + + + + + + + +
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
+
+ + + + + + + + + + + + + + + + +
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
KEY_POSITION KEY_ARTISTLINK
+ +
+ + + diff --git a/website/start.py b/website/start.py new file mode 100644 index 0000000..aa89b06 --- /dev/null +++ b/website/start.py @@ -0,0 +1,34 @@ +import urllib +import json + + +def replacedict(keys,dbport): + from utilities import getArtistInfo, getArtistsInfo + from htmlgenerators import artistLink, artistLinks, trackLink, scrobblesArtistLink, keysToUrl, pickKeys, clean + + clean(keys) + timekeys = pickKeys(keys,"since","to","in") + limitkeys = pickKeys(keys) + + # get chart data + response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/charts/artists?" + keysToUrl(timekeys,limitkeys)) + db_data = json.loads(response.read()) + charts = db_data["list"][:50] + topartist = charts[0]["artist"] + + chartslist = [c["artist"] for c in charts] + #chartslistimg = [getArtistInfo(a).get("image") for a in chartslist] + chartslistimg = [info.get("image") for info in getArtistsInfo(chartslist)] + chartslistlink = [artistLink(a) for a in chartslist] + + + # get total amount of scrobbles + response = urllib.request.urlopen("http://localhost:" + str(dbport) + "/scrobbles?" + keysToUrl(timekeys,limitkeys)) + db_data = json.loads(response.read()) + scrobblelist = db_data["list"] + scrobbles = len(scrobblelist) + + + + return {"KEY_ARTISTIMAGE":chartslistimg,"KEY_ARTISTNAME":chartslist,"KEY_ARTISTLINK":chartslistlink,"KEY_POSITION":["#" + str(i) for i in range(1,50)]} +