music update
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 4m39s

This commit is contained in:
2026-02-02 01:24:14 +00:00
parent 067f0e189d
commit 9700a5dc7f
5 changed files with 36 additions and 18 deletions

26
src/routes/lastfm.py Normal file
View File

@@ -0,0 +1,26 @@
from flask import Blueprint, jsonify
from os import getenv as env
import logging, requests
# Create blueprint
bp = Blueprint(
'lastfm',
__name__,
template_folder=env('TEMPLATE_FOLDER', default='../templates'),
static_folder=env('STATIC_FOLDER', default='../static')
)
# Create logger
log = logging.getLogger(__name__)
# lastfm info
@bp.route('/info')
def lastfm_info():
url = f"http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user={env('LASTFM_USER')}&api_key={env('LASTFM_API_KEY')}&format=json&limit=1"
response = requests.get(url).json()
data = {
'artist': response['recenttracks']['track'][0]['artist']['#text'],
'track': response['recenttracks']['track'][0]['name'],
'image': response['recenttracks']['track'][0]['image'][3]['#text']
}
return jsonify(data)