added fmframework

This commit is contained in:
aj 2019-10-08 18:58:26 +01:00
parent 2709aecd89
commit 83900a12dd
2 changed files with 5 additions and 21 deletions

View File

@ -1,6 +1,5 @@
from flask import Blueprint, render_template from flask import Blueprint, render_template
import requests from fmframework.net.network import Network
from google.cloud import firestore from google.cloud import firestore
fs = firestore.Client() fs = firestore.Client()
@ -14,22 +13,7 @@ music_print = Blueprint('music', __name__, template_folder='templates')
@music_print.route('/') @music_print.route('/')
def root(): def root():
fmkey = fs.document('key/fm').get().to_dict()['clientid'] fmkey = fs.document('key/fm').get().to_dict()['clientid']
fmnet = Network(username='sarsoo', api_key=fmkey)
params = { albums = fmnet.get_top_albums(Network.Range.MONTH, limit=6)
'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']
return render_template('music/index.html', albums=albums) return render_template('music/index.html', albums=albums)

View File

@ -9,9 +9,9 @@
<div class="row"> <div class="row">
{% for album in albums %} {% for album in albums %}
<div class = "pad-2 card"> <div class = "pad-2 card">
<img src="{{album.image[3].text}}"> <img src="{{album.images[-1].link}}">
<p style="text-align:center">{{ album.name }}<br>{{ album.artist.name -}}</p> <p style="text-align:center">{{ album.name }}<br>{{ album.artist.name -}}</p>
<p style="text-align:center">{{- album.playcount }} plays</p> <p style="text-align:center">{{- album.play_count }} plays</p>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>