2023-02-26 19:24:11 +00:00
|
|
|
from flask import Flask, render_template, request, jsonify
|
2023-02-05 14:19:21 +00:00
|
|
|
from flask_compress import Compress
|
|
|
|
|
2023-02-05 14:35:50 +00:00
|
|
|
import dotenv
|
2023-02-26 19:24:11 +00:00
|
|
|
|
2023-02-05 14:19:21 +00:00
|
|
|
from random import choice
|
|
|
|
import json
|
2023-02-26 19:24:11 +00:00
|
|
|
import requests
|
2022-12-28 00:46:08 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
# Getting color palette from album art
|
|
|
|
import colorthief
|
2022-12-28 00:46:08 +00:00
|
|
|
|
2023-02-05 14:35:50 +00:00
|
|
|
LASTFM_API_KEY = dotenv.get_key('./.env', 'LASTFM')
|
|
|
|
|
2022-12-28 00:46:08 +00:00
|
|
|
app = Flask(__name__)
|
2023-02-05 14:19:21 +00:00
|
|
|
Compress(app)
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# ROUTES
|
|
|
|
#
|
|
|
|
@app.route('/')
|
|
|
|
def index():
|
2023-02-27 00:42:49 +00:00
|
|
|
msg = [
|
|
|
|
'Don\'t cry because it\'s over, smile because it happened',
|
|
|
|
'This could go one of two ways...', 'Gwa Gwa',
|
|
|
|
'It\'s a UNIX system! I know this!', '*internal screaming*',
|
|
|
|
'Don\'t forget to drink water!', 'I wish we were better strangers.',
|
|
|
|
'If I were you, I\'d run now', 'SILICA GEL "DO NOT EAT".',
|
|
|
|
'Gods die too.', 'Eat hotchip and lie'
|
|
|
|
]
|
|
|
|
|
2023-02-05 14:19:21 +00:00
|
|
|
return render_template('index.html', msg=choice(msg))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/cretura')
|
|
|
|
def cretura():
|
|
|
|
return render_template('cretura.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/about')
|
|
|
|
def about():
|
2023-02-27 00:42:49 +00:00
|
|
|
"""
|
|
|
|
Returns a dict with all the languages I know and their level of knowledge
|
|
|
|
0 = Absolute beginner
|
|
|
|
1 = Basics
|
|
|
|
2 = Intermediate
|
|
|
|
3 = Advanced
|
|
|
|
4 = Expert
|
|
|
|
5 = Undefeated
|
|
|
|
"""
|
|
|
|
languages = {
|
|
|
|
'Python': {
|
|
|
|
'level': 3,
|
|
|
|
'since': '2020',
|
|
|
|
'color': '#3776AB',
|
|
|
|
},
|
|
|
|
'HTML': {
|
|
|
|
'level': 4,
|
|
|
|
'since': '2021',
|
|
|
|
'color': '#E34F26',
|
|
|
|
},
|
|
|
|
'CSS': {
|
|
|
|
'level': 3,
|
|
|
|
'since': '2021',
|
|
|
|
'color': '#1572B6',
|
|
|
|
},
|
|
|
|
'JavaScript': {
|
|
|
|
'level': 2,
|
|
|
|
'since': '2022',
|
|
|
|
'color': '#F7DF1E',
|
|
|
|
},
|
|
|
|
'Sass/SCSS': {
|
|
|
|
'level': 4,
|
|
|
|
'since': '2022',
|
|
|
|
'color': '#CC6699',
|
|
|
|
},
|
|
|
|
'PHP': {
|
|
|
|
'level': 2,
|
|
|
|
'since': '2022',
|
|
|
|
'color': '#777BB4',
|
|
|
|
},
|
|
|
|
'SQL': {
|
|
|
|
'level': 1,
|
|
|
|
'since': '2022',
|
|
|
|
'color': '#4479A1',
|
|
|
|
},
|
|
|
|
'Scratch': {
|
|
|
|
'level': 5,
|
|
|
|
'since': '2015',
|
|
|
|
'color': '#FFD500',
|
|
|
|
},
|
|
|
|
'Shell': {
|
|
|
|
'level': 2,
|
|
|
|
'since': '2021',
|
|
|
|
'color': '#89E051',
|
|
|
|
},
|
|
|
|
'Rust': {
|
|
|
|
'level': 0,
|
|
|
|
'since': '2023',
|
|
|
|
'color': '#CE422B',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
systems = {
|
|
|
|
'Ubuntu': {
|
|
|
|
'level': 2,
|
|
|
|
'since': '2022',
|
|
|
|
'color': '#E95420',
|
|
|
|
},
|
|
|
|
'Arch': {
|
|
|
|
'level': 3,
|
|
|
|
'since': '2021',
|
|
|
|
'color': '#1793D1',
|
|
|
|
},
|
|
|
|
'Proxmox': {
|
|
|
|
'level': 2,
|
|
|
|
'since': '2021',
|
|
|
|
'color': '#E57000',
|
|
|
|
},
|
|
|
|
'Windows': {
|
|
|
|
'level': 1,
|
|
|
|
'since': '2011',
|
|
|
|
'color': '#0078D6',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return render_template('about.html', languages=languages, systems=systems)
|
2023-02-05 14:19:21 +00:00
|
|
|
|
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
@app.route('/music', methods=['GET', 'POST'])
|
2023-02-05 14:19:21 +00:00
|
|
|
def music():
|
2023-02-26 19:24:11 +00:00
|
|
|
if request.method == 'POST':
|
|
|
|
current_tracks = requests.get(
|
2023-02-27 00:42:49 +00:00
|
|
|
f'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=Fluffy_Bean_&api_key={LASTFM_API_KEY}&limit=5&format=json'
|
|
|
|
)
|
2023-02-26 19:24:11 +00:00
|
|
|
current_tracks = json.loads(current_tracks.text)
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
tracks = []
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
for track in current_tracks['recenttracks']['track']:
|
|
|
|
# As django is weird with @attr in json data
|
|
|
|
# I make a new dict with a bool for nowPlaying
|
|
|
|
nowPlaying = False
|
|
|
|
if '@attr' in track:
|
|
|
|
nowPlaying = True
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
# Yoink color palette from album art
|
2023-02-27 00:42:49 +00:00
|
|
|
color_thief = colorthief.ColorThief(
|
|
|
|
requests.get(track['image'][2]['#text'], stream=True).raw)
|
2023-02-26 19:24:11 +00:00
|
|
|
palette = color_thief.get_palette()
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
tmp_track = {
|
|
|
|
'name': track['name'],
|
|
|
|
'artist': track['artist']['#text'],
|
|
|
|
'album': track['album']['#text'],
|
|
|
|
'url': track['url'],
|
|
|
|
'image': track['image'][2]['#text'],
|
|
|
|
'nowPlaying': nowPlaying,
|
|
|
|
'palette': palette[0]
|
|
|
|
}
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
tracks.append(tmp_track)
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
return jsonify(tracks)
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2023-02-26 19:24:11 +00:00
|
|
|
# GET request
|
|
|
|
return render_template('music.html')
|
2022-12-28 00:46:08 +00:00
|
|
|
|
2023-02-27 00:42:49 +00:00
|
|
|
|
2022-12-28 00:46:08 +00:00
|
|
|
#
|
|
|
|
# ERROR HANDLERS
|
|
|
|
#
|
|
|
|
@app.errorhandler(405)
|
|
|
|
def method_not_allowed(e):
|
|
|
|
error = '405'
|
|
|
|
msg = 'Method sussy wussy'
|
|
|
|
return render_template('error.html', error=error, msg=msg), 404
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def page_not_found(e):
|
|
|
|
error = '404'
|
|
|
|
msg = 'Could not find what you need!'
|
|
|
|
return render_template('error.html', error=error, msg=msg), 404
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(403)
|
|
|
|
def forbidden(e):
|
|
|
|
error = '403'
|
|
|
|
msg = 'Go away! This is no place for you!'
|
|
|
|
return render_template('error.html', error=error, msg=msg), 403
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(410)
|
|
|
|
def gone(e):
|
|
|
|
error = '410'
|
|
|
|
msg = 'The page is no longer available! *sad face*'
|
|
|
|
return render_template('error.html', error=error, msg=msg), 410
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(500)
|
|
|
|
def internal_server_error(e):
|
|
|
|
error = '500'
|
|
|
|
msg = 'Server died inside :c'
|
2023-02-05 14:19:21 +00:00
|
|
|
return render_template('error.html', error=error, msg=msg), 500
|