From d1391cf38bff968a1cf95135084a4017b732c3df Mon Sep 17 00:00:00 2001 From: novatorem Date: Sun, 23 Aug 2020 11:18:07 -0400 Subject: [PATCH] Revert "Recently playing mod" --- README.md | 16 ++++++------ api/spotify-playing.py | 47 +++++++++++++++++++---------------- api/templates/preview.html | 8 +++--- api/templates/spotify.html.j2 | 17 ++++++------- 4 files changed, 47 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index b27b9ea..ce6e172 100644 --- a/README.md +++ b/README.md @@ -8,11 +8,13 @@ Software Developer currently working on cool projects at [Cast](https://blacktrax.cast-soft.com/showcase/). Everything here is available under the [Unlicense](https://choosealicense.com/licenses/unlicense/)! -

- [![Website](https://img.shields.io/badge/website-dev-2a8?style=flat-square&logo=safari&logoColor=white)](https://novac.dev) - [![E-Mail](https://img.shields.io/badge/email-reveal-369?style=flat-square&logo=gmail&logoColor=white)](https://mailhide.io/e/5ck1H)
- [![Spotify](https://img.shields.io/badge/spotify-omni-1DB954?style=flat-square&logo=spotify&logoColor=white)](https://open.spotify.com/user/omnitenebris) - [![Visits](https://badges.pufler.dev/visits/novatorem/novatorem?logo=GitHub&label=github%20visits&color=blue&logoColor=white&style=flat-square)](https://github.com/novatorem) -

+

+ [![Website](https://img.shields.io/badge/website-dev-2a8?style=flat-square&logo=safari&logoColor=white)](https://novac.dev) + [![E-Mail](https://img.shields.io/badge/email-reveal-369?style=flat-square&logo=gmail&logoColor=white)](https://mailhide.io/e/5ck1H)
+ [![Spotify](https://img.shields.io/badge/spotify-omni-1DB954?style=flat-square&logo=spotify&logoColor=white)](https://open.spotify.com/user/omnitenebris) + [![Visits](https://badges.pufler.dev/visits/novatorem/novatorem?logo=GitHub&label=github%20visits&color=blue&logoColor=white&style=flat-square)](https://github.com/novatorem) +

- \ No newline at end of file + + +[//]: <> (The ` ` is to have Aphelion take up more space) diff --git a/api/spotify-playing.py b/api/spotify-playing.py index 399419d..e34e153 100644 --- a/api/spotify-playing.py +++ b/api/spotify-playing.py @@ -1,30 +1,31 @@ -import os -import json -import random -import requests - -from base64 import b64encode -from dotenv import load_dotenv, find_dotenv from flask import Flask, Response, jsonify, render_template +from base64 import b64encode +from dotenv import load_dotenv, find_dotenv load_dotenv(find_dotenv()) +import requests +import json +import os +import random + SPOTIFY_CLIENT_ID = os.getenv("SPOTIFY_CLIENT_ID") SPOTIFY_SECRET_ID = os.getenv("SPOTIFY_SECRET_ID") SPOTIFY_REFRESH_TOKEN = os.getenv("SPOTIFY_REFRESH_TOKEN") -# Scopes: -# user-read-currently-playing -# user-read-recently-played +# scope user-read-currently-playing/user-read-recently-played SPOTIFY_URL_REFRESH_TOKEN = "https://accounts.spotify.com/api/token" SPOTIFY_URL_NOW_PLAYING = "https://api.spotify.com/v1/me/player/currently-playing" SPOTIFY_URL_RECENTLY_PLAY = "https://api.spotify.com/v1/me/player/recently-played?limit=10" + app = Flask(__name__) + def getAuth(): return b64encode(f"{SPOTIFY_CLIENT_ID}:{SPOTIFY_SECRET_ID}".encode()).decode("ascii") + def refreshToken(): data = { "grant_type": "refresh_token", @@ -47,8 +48,11 @@ def recentlyPlayed(): return response.json() def nowPlaying(): + token = refreshToken() + headers = {"Authorization": f"Bearer {token}"} + response = requests.get(SPOTIFY_URL_NOW_PLAYING, headers=headers) if response.status_code == 204: @@ -78,24 +82,24 @@ def makeSVG(data): barCSS = barGen(barCount) if data == {}: - #contentBar = "" - recentlyPlays = recentlyPlayed() - recentLength = len(recentlyPlays["items"]) - itemIndex = random.randint(0, recentLength - 1) - item = recentlyPlays["items"][itemIndex]["track"] + content_bar = "" + recent_plays = recentlyPlayed() + size_recent_play = len(recent_plays["items"]) + idx = random.randint(0, size_recent_play - 1) + item = recent_plays["items"][idx]["track"] else: item = data["item"] - image = loadImageB64(item["album"]["images"][1]["url"]) + img = loadImageB64(item["album"]["images"][1]["url"]) artistName = item["artists"][0]["name"].replace("&", "&") songName = item["name"].replace("&", "&") dataDict = { - "contentBar": contentBar, - "barCSS": barCSS, - "artistName": artistName, - "songName": songName, - "image": image + "content_bar": contentBar, + "css_bar": barCSS, + "artist_name": artistName, + "song_name": songName, + "img": img, } return render_template("spotify.html.j2", **dataDict) @@ -103,6 +107,7 @@ def makeSVG(data): @app.route("/", defaults={"path": ""}) @app.route("/") def catch_all(path): + data = nowPlaying() svg = makeSVG(data) diff --git a/api/templates/preview.html b/api/templates/preview.html index f9449a2..a6c12e0 100644 --- a/api/templates/preview.html +++ b/api/templates/preview.html @@ -61,11 +61,9 @@ } .cover { - position: absolute; border-radius: 5px; height: 100px; width: 100px; - z-index: -1; } #bars { @@ -101,14 +99,16 @@
- +
Song
Arist
-
Bars
+
+ {{content_bar|safe}} +
diff --git a/api/templates/spotify.html.j2 b/api/templates/spotify.html.j2 index 299144c..d9d9a5d 100644 --- a/api/templates/spotify.html.j2 +++ b/api/templates/spotify.html.j2 @@ -43,9 +43,9 @@ color: #666; text-align: center; margin-top: 3px; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; + white-space:nowrap; + overflow:hidden; + text-overflow:ellipsis; } .artist { @@ -53,7 +53,6 @@ color: #b3b3b3; text-align: center; margin-bottom: 5px; - margin-top: 5px; } .logo { @@ -98,19 +97,19 @@ {{css_bar|safe}} - +
- +
-
{{songName}}
-
{{artistName}}
+
{{song_name}}
+
{{artist_name}}
- {{contentBar|safe}} + {{content_bar|safe}}