From 83900a12dd0f59797f803bdbf6f1896c29f8ba4a Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 8 Oct 2019 18:58:26 +0100 Subject: [PATCH] added fmframework --- sarsoo/music/music.py | 22 +++------------------- sarsoo/music/templates/music/index.html | 4 ++-- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/sarsoo/music/music.py b/sarsoo/music/music.py index d4bc338..9c953a8 100644 --- a/sarsoo/music/music.py +++ b/sarsoo/music/music.py @@ -1,6 +1,5 @@ from flask import Blueprint, render_template -import requests - +from fmframework.net.network import Network from google.cloud import firestore fs = firestore.Client() @@ -14,22 +13,7 @@ music_print = Blueprint('music', __name__, template_folder='templates') @music_print.route('/') def root(): fmkey = fs.document('key/fm').get().to_dict()['clientid'] - - params = { - 'method': 'user.gettopalbums', - 'user': 'sarsoo', - 'period': '1month', - 'limit': '6', - 'api_key': fmkey, - 'format': 'json' - } - - req = requests.get(fm_url, params=params) - - albums = req.json()['topalbums']['album'] - - for album in albums: - for image in album['image']: - image['text'] = image['#text'] + fmnet = Network(username='sarsoo', api_key=fmkey) + albums = fmnet.get_top_albums(Network.Range.MONTH, limit=6) return render_template('music/index.html', albums=albums) diff --git a/sarsoo/music/templates/music/index.html b/sarsoo/music/templates/music/index.html index f7d0d7d..365e343 100644 --- a/sarsoo/music/templates/music/index.html +++ b/sarsoo/music/templates/music/index.html @@ -9,9 +9,9 @@
{% for album in albums %}
- +

{{ album.name }}
{{ album.artist.name -}}

-

{{- album.playcount }} plays

+

{{- album.play_count }} plays

{% endfor %}