diff --git a/app/app.py b/app/app.py index 3492a78..d3f6ba5 100644 --- a/app/app.py +++ b/app/app.py @@ -2,6 +2,7 @@ import glob import configparser import random +import requests import flask import waitress import markdown @@ -19,6 +20,9 @@ STATUS_FILE = config['STATUS']['STATUS_FILE'] PORT = int(config['NETWORK']['PORT']) DEV = int(config['NETWORK']['DEV']) +MUSIC_API_TOKEN = config['AUTH']['MUSIC_API_TOKEN'] +MUSIC_API_URL = config['NETWORK']['MUSIC_API_URL'] + def get_posts(category_filter : str | None = None) -> list[Post]: post_files = glob.glob(f'{POSTS_FOLDER}/*') try: @@ -105,7 +109,25 @@ def music(): # Get status status = get_status() - return flask.render_template('music.html', posts=post_bodies, status=status) + # Get top albums + r = requests.get( + MUSIC_API_URL +'/top/albums', + headers={ + 'token' : MUSIC_API_TOKEN, + 'user' : '1', + 'limit' : '9' + }) + + top_albums = r.json()['top'] + for album_index in range(0, len(top_albums)): + album = top_albums[album_index] + + time = int(album['listen_time']) + hours = round(time/1000/60/60, 1) + + top_albums[album_index]['listen_time'] = hours + + return flask.render_template('music.html', posts=post_bodies, status=status, top_albums=top_albums) # Motion Pictures Page @app.route('/motion-pictures/') @@ -148,6 +170,38 @@ def about(): return flask.render_template('about.html', status=status) +# MISC + +@app.route('/albumsquare//') +def album_square(user_id, rows : int): + + limit = rows ** 2 + + res = 100/(rows+2) + + # Get top albums + r = requests.get( + MUSIC_API_URL +'/top/albums', + headers={ + 'token' : MUSIC_API_TOKEN, + 'user' : user_id, + 'limit' : str(limit) + }) + + top_albums = r.json()['top'] + for album_index in range(0, len(top_albums)): + album = top_albums[album_index] + + time = int(album['listen_time']) + hours = round(time/1000/60/60, 1) + + top_albums[album_index]['listen_time'] = hours + + + return flask.render_template('album_square.html', top_albums=top_albums, limit=rows, res=res) + + + if __name__ == "__main__": if DEV: app.run(port=PORT) diff --git a/app/data/.flask_session/2029240f6d1128be89ddc32729463129 b/app/data/.flask_session/2029240f6d1128be89ddc32729463129 new file mode 100644 index 0000000..7f5741f Binary files /dev/null and b/app/data/.flask_session/2029240f6d1128be89ddc32729463129 differ diff --git a/app/data/.flask_session/aa43147407c8a8c678cd91f678f2a023 b/app/data/.flask_session/aa43147407c8a8c678cd91f678f2a023 new file mode 100644 index 0000000..d818306 Binary files /dev/null and b/app/data/.flask_session/aa43147407c8a8c678cd91f678f2a023 differ diff --git a/app/data/comments.json b/app/data/comments.json new file mode 100644 index 0000000..964e9aa --- /dev/null +++ b/app/data/comments.json @@ -0,0 +1,8 @@ +{ + "2" : [ + { + "username" : "0x01FE", + "content" : "Hello, this is an example comment!" + } + ] +} diff --git a/app/data/users.json b/app/data/users.json new file mode 100644 index 0000000..c3227f9 --- /dev/null +++ b/app/data/users.json @@ -0,0 +1,5 @@ +{ + "users" : { + "0x01FE" : "cGFzc3dvcmQ=" + } +} diff --git a/app/static/albumsquare.css b/app/static/albumsquare.css new file mode 100644 index 0000000..0f1cb6c --- /dev/null +++ b/app/static/albumsquare.css @@ -0,0 +1,31 @@ +.albums { + height: 100%; + height: fit-content; + align-self: flex-start; + + border-style: var(--borders-style); + border-radius: var(--border-radius); + border-color: #1E2022; + background-color: var(--main-background); + + /* Text Settings + font-weight: bold; + line-height: 30pt; */ + line-height: 0; + font-size: 0; +} + +.albums img { + height: 100px; + width: 100px; + padding: 0 0; + margin: 0 0; + border: 0 0; +} + + +.body { + height: 100%; + padding: 0 0; + margin: 0 0; +} diff --git a/app/static/style.css b/app/static/style.css index d657243..ace95c1 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -172,3 +172,41 @@ a:hover { line-height: 2.25; text-indent: 3em; } + +/* MUSIC */ +.albums { + height: fit-content; + align-self: flex-start; + top: 10px; + + padding: 20pt; + + margin: 5em 0; + margin-right: 2em; + + border-style: var(--borders-style); + border-radius: var(--border-radius); + border-color: #1E2022; + background-color: var(--main-background); + + /* Text Settings + font-weight: bold; + line-height: 30pt; */ + line-height: 0; + font-size: 0; +} + +.albums img { + height: 100px; + width: 100px; + padding: 0 0; + margin: 0 0; + border: 0 0; +} + +.albums h1 { + font-size: normal; + text-align: center; + padding: 0.5em 0; +} + diff --git a/app/templates/album_square.html b/app/templates/album_square.html new file mode 100644 index 0000000..dfd49b7 --- /dev/null +++ b/app/templates/album_square.html @@ -0,0 +1,20 @@ + + +
+ + + Album Square +
+ +
+ {% for album in top_albums %} + + + + {% if loop.index % limit == 0 %} +
+ {% endif %} + {% endfor %} +
+ + diff --git a/app/templates/music.html b/app/templates/music.html index 9a00a11..5e35363 100644 --- a/app/templates/music.html +++ b/app/templates/music.html @@ -28,6 +28,18 @@
{{ post|safe }}
{% endfor %} + +
+

Top Albums

+ {% for album in top_albums %} + + + + {% if loop.index % 3 == 0 %} +
+ {% endif %} + {% endfor %} +