music update
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 4m39s
All checks were successful
Build and push container image / build-and-push-image (push) Successful in 4m39s
This commit is contained in:
26
src/routes/lastfm.py
Normal file
26
src/routes/lastfm.py
Normal 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)
|
||||
Reference in New Issue
Block a user