def get_stats():
'''Music library statistics'''
page_format = request.args.get('format', 'html')
collection = app.config['COLLECTION']
stats = webfilter(partial(collection.stats, cursor_factory=RealDictCursor))
def bytesToHuman(b):
return humanfriendly.format_size(b)
def secondsToHuman(s):
import datetime
return str(datetime.timedelta(seconds=s))
if page_format == 'html':
return render_template("stats.html", stats=stats, bytesToHuman=bytesToHuman, secondsToHuman=secondsToHuman)
elif page_format == 'json':
return dumps(stats)
return ('Invalid format, available: json,html', 400)
评论列表
文章目录