diff --git a/README.md b/README.md index d8282e3..c9fa882 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,5 @@ Code of the website hosted at https://www.0x01fe.net -Could I gitignore the config files? -Yes. -Do I? -no. +One might ask why my pretty simple website is written in Python. The answer is so that I can just drop markdown files in a folder and have them automatically formatted and uploaded. This is done using the fact that markdown translates to HTML perfectly and that Flask / Jinja2 templates are really easy to use! diff --git a/app/app.py b/app/app.py index 3492a78..a7e1217 100644 --- a/app/app.py +++ b/app/app.py @@ -1,7 +1,10 @@ +import os import glob import configparser import random +import datetime +import requests import flask import waitress import markdown @@ -14,11 +17,15 @@ CONFIG_PATH = "./config.ini" config = configparser.ConfigParser() config.read(CONFIG_PATH) +WRITING_FOLDER = 'static/writing/' POSTS_FOLDER = config['POSTS']['POSTS_FOLDER'] 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 +112,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/') @@ -139,6 +164,31 @@ def programming(): return flask.render_template('programming.html', posts=post_bodies, status=status) +@app.route('/writing/') +def writing(): + + works = [] + + # Get all works in writing folder + files = glob.glob(WRITING_FOLDER + '*') + + for path in files: + + date: str = datetime.datetime.fromtimestamp(os.path.getctime(path)).strftime("%B %d, %Y") + name: str = path.split('/')[-1] + + works.append({ + 'date' : date, + 'name' : name, + 'path' : path + }) + + return flask.render_template('writing.html', works=works) + + + + + # About Page @app.route('/about/') def about(): @@ -148,6 +198,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 = (1080/(rows))-rows + + # 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..1044b3d --- /dev/null +++ b/app/static/albumsquare.css @@ -0,0 +1,19 @@ +.albums { + height: 100%; + + line-height: 0; + font-size: 0; +} + +.albums img { + padding: 0 0; + margin: 0 0; + border: 0 0; +} + + +.body { + height: 100%; + padding: 0 0; + margin: 0 0; +} diff --git a/app/static/programming/vscode_extensions.txt b/app/static/programming/vscode_extensions.txt new file mode 100644 index 0000000..a0edf1d --- /dev/null +++ b/app/static/programming/vscode_extensions.txt @@ -0,0 +1,12 @@ +EOF Mark, +Glassit-VSC, +JSON formatter, +Pylance, +Remote - SSH, +Synthwave '84 Blues, +Trailing Spaces, +Helm Intellisense, +background, +Helium Icon Theme, +SQLite Viewer, +Docker \ No newline at end of file diff --git a/app/static/style.css b/app/static/style.css index d657243..67ad496 100644 --- a/app/static/style.css +++ b/app/static/style.css @@ -107,6 +107,39 @@ a:hover { text-decoration: none; } +.rightbar { + 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); + + opacity: 0.9; + + /* box-shadow: -10px 10px var(--accent); */ + + /* Text Settings */ + font-weight: bold; + line-height: 30pt; +} + +.rightbar a { + text-decoration: none; +} + +.rightbar h2 { + font-family: Georgia, 'Times New Roman', Times, serif; + line-height: normal; +} + .dlog { flex: 3; @@ -172,3 +205,49 @@ 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; */ +} + + +.real-albums img { + height: 100px; + width: 100px; + padding: 0 0; + margin: 0 0; + border: 0 0; +} + +.real-albums { + line-height: 0; + font-size: 0; + padding: 0 0; + margin: 0 0; +} + +.albums h1 { + font-size: 2em; + text-align: center; + padding: 0 0; + margin: 15pt 0; + margin-top: -5pt; +} + diff --git a/app/static/writing.html b/app/static/writing.html deleted file mode 100644 index 44de92c..0000000 --- a/app/static/writing.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - home -
-
- Scream March 27th, 2024 - - \ No newline at end of file diff --git a/app/templates/about.html b/app/templates/about.html index a2663fc..ce7774c 100644 --- a/app/templates/about.html +++ b/app/templates/about.html @@ -18,6 +18,7 @@ Music
Motion Picture
Programming
+ Writing
About diff --git a/app/templates/album_square.html b/app/templates/album_square.html new file mode 100644 index 0000000..ca6d024 --- /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/games.html b/app/templates/games.html index d023f8b..0ffded7 100644 --- a/app/templates/games.html +++ b/app/templates/games.html @@ -18,6 +18,7 @@ Music
Motion Picture
Programming
+ Writing
About diff --git a/app/templates/index.html b/app/templates/index.html index 51412b8..def98bd 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -18,7 +18,7 @@ Music
Motion Picture
Programming
- Writing
+ Writing
About diff --git a/app/templates/motion-pictures.html b/app/templates/motion-pictures.html index 459f655..87d36f9 100644 --- a/app/templates/motion-pictures.html +++ b/app/templates/motion-pictures.html @@ -18,6 +18,7 @@ Music
Motion Picture
Programming
+ Writing
About diff --git a/app/templates/music.html b/app/templates/music.html index 9a00a11..5ea89f3 100644 --- a/app/templates/music.html +++ b/app/templates/music.html @@ -18,6 +18,7 @@ Music
Motion Picture
Programming
+ Writing
About @@ -28,6 +29,20 @@
{{ post|safe }}
{% endfor %} + +
+

Top Albums

+
+ {% for album in top_albums %} + + + + {% if loop.index % 3 == 0 %} +
+ {% endif %} + {% endfor %} +
+
diff --git a/app/templates/programming.html b/app/templates/programming.html index 91a5a31..d146ccd 100644 --- a/app/templates/programming.html +++ b/app/templates/programming.html @@ -18,6 +18,7 @@ Music
Motion Picture
Programming
+ Writing
About @@ -28,6 +29,12 @@
{{ post|safe }}
{% endfor %} + + +
+

Other

+ Technologies I Use +
diff --git a/app/templates/writing.html b/app/templates/writing.html new file mode 100644 index 0000000..09df245 --- /dev/null +++ b/app/templates/writing.html @@ -0,0 +1,11 @@ + + + + home +
+
+ {% for work in works %} + {{ work.name }} {{ work.date }} + {% endfor %} + + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index bb91e2f..85ba8d2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ Markdown==3.5.2 Flask==2.2.3 waitress==2.1.2 -Werkzeug==2.2.3 \ No newline at end of file +Werkzeug==2.2.3 +requests==2.31.0 \ No newline at end of file