From 5f2e500dc8def558f98031321f2e3520556861d3 Mon Sep 17 00:00:00 2001 From: Ethan Shoham Date: Fri, 9 Jul 2021 20:39:46 +0300 Subject: [PATCH] Easy way to add more thems, added a dark theme --- api/spotify.py | 12 +++- api/templates/spotify-dark.html.j2 | 112 +++++++++++++++++++++++++++++ api/templates/spotify.html.j2 | 5 +- 3 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 api/templates/spotify-dark.html.j2 diff --git a/api/spotify.py b/api/spotify.py index 5ed3e44..874944e 100644 --- a/api/spotify.py +++ b/api/spotify.py @@ -5,7 +5,7 @@ import requests from base64 import b64encode from dotenv import load_dotenv, find_dotenv -from flask import Flask, Response, jsonify, render_template +from flask import Flask, Response, jsonify, render_template, templating load_dotenv(find_dotenv()) @@ -17,6 +17,8 @@ SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID") SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID") SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN") +TEMPLATE_THEME = "dark" + REFRESH_TOKEN_URL = "https://accounts.spotify.com/api/token" NOW_PLAYING_URL = "https://api.spotify.com/v1/me/player/currently-playing" RECENTLY_PLAYING_URL = ( @@ -82,6 +84,12 @@ def barGen(barCount): left += 4 return barCSS +def template(theme): + return{ + 'dark':'spotify-dark.html.j2', + 'light':'spotify.html.js' + }[theme.lower()] + def loadImageB64(url): resposne = requests.get(url) @@ -121,7 +129,7 @@ def makeSVG(data): "status": currentStatus, } - return render_template("spotify.html.j2", **dataDict) + return render_template(template(TEMPLATE_THEME), **dataDict) @app.route("/", defaults={"path": ""}) diff --git a/api/templates/spotify-dark.html.j2 b/api/templates/spotify-dark.html.j2 new file mode 100644 index 0000000..5d832b8 --- /dev/null +++ b/api/templates/spotify-dark.html.j2 @@ -0,0 +1,112 @@ + + +
+ + + + +
+ +
+ +
+
+ +
+
{{songName}}
+
{{artistName}}
+
{{contentBar|safe}}
+
+
+ +
+
+
\ No newline at end of file diff --git a/api/templates/spotify.html.j2 b/api/templates/spotify.html.j2 index 9e5bf4c..a2614ac 100644 --- a/api/templates/spotify.html.j2 +++ b/api/templates/spotify.html.j2 @@ -18,7 +18,6 @@ .container { border-radius: 5px; padding: 10px 10px 10px 0px; - background-color:#181414; } .art { @@ -32,7 +31,7 @@ } .song { - color: #f7f7f7; + color: #666; overflow:hidden; margin-top: 3px; font-size: 24px; @@ -42,7 +41,7 @@ } .artist { - color: #9f9f9f; + color: #b3b3b3; font-size: 20px; margin-top: 4px; text-align: center;