All checks were successful
Build and push container image / build-and-push-image (push) Successful in 4m39s
26 lines
838 B
Python
26 lines
838 B
Python
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) |