From 108f3cf21add6df38413ae39befea785e8025b87 Mon Sep 17 00:00:00 2001 From: Ethan Shoham Date: Sun, 11 Jul 2021 08:49:18 +0300 Subject: [PATCH] Themes and Templates setup guide --- SetUp.md | 10 ++++++++++ api/spotify.py | 19 +++++++++---------- api/templates.json | 7 +++++++ 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 api/templates.json diff --git a/SetUp.md b/SetUp.md index c6dcc195..4e43c1a0 100644 --- a/SetUp.md +++ b/SetUp.md @@ -65,6 +65,16 @@ Have a string saying either "Vibing to:" or "Last seen playing:". * Uncomment [**.main**'s `margin-top`](https://github.com/novatorem/novatorem/blob/5194a689253ee4c89a9d365260d6050923d93dd5/api/templates/spotify.html.j2#L10) * Uncomment [currentStatus](https://github.com/novatorem/novatorem/blob/5194a689253ee4c89a9d365260d6050923d93dd5/api/templates/spotify.html.j2#L93) +### Theme Templates + +If you want to change the widget theme, you can do so by the changing the `current-theme` property in the `templates.json` file. + +Themes: +* `light` +* `dark` + +If you wish to customize farther, you can add your own customized `spotify.html.j2` file to the templates folder, and add the theme and file name to the `templates` dictionary in the `templates.json` file. + ## Requests Customization requests can be submitted as an issue, like https://github.com/novatorem/novatorem/issues/2 diff --git a/api/spotify.py b/api/spotify.py index fe034a31..67ab32f2 100644 --- a/api/spotify.py +++ b/api/spotify.py @@ -17,10 +17,7 @@ SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID") SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN") -######################### -# change theme light/dark - -TEMPLATE_THEME = "dark" +FALLBACK_THEME = "spotify.html.j2" REFRESH_TOKEN_URL = "https://accounts.spotify.com/api/token" NOW_PLAYING_URL = "https://api.spotify.com/v1/me/player/currently-playing" @@ -87,11 +84,13 @@ def barGen(barCount): left += 4 return barCSS -def getTemplate(theme): - return{ - 'dark':'spotify-dark.html.j2', - 'light':'spotify.html.js' - }[theme.lower()] +def getTemplate(): + try: + file = open("templates.json",) + templates = json.load(file) + return templates["templates"][templates["current-theme"]] + except: + return FALLBACK_THEME def loadImageB64(url): @@ -132,7 +131,7 @@ def makeSVG(data): "status": currentStatus, } - return render_template(getTemplate(TEMPLATE_THEME), **dataDict) + return render_template(getTemplate(), **dataDict) @app.route("/", defaults={"path": ""}) diff --git a/api/templates.json b/api/templates.json new file mode 100644 index 00000000..94f34feb --- /dev/null +++ b/api/templates.json @@ -0,0 +1,7 @@ +{ + "current-theme": "light", + "templates": { + "light": "spotify.html.j2", + "dark": "spotify-dark.html.j2" + } +} \ No newline at end of file