def list_artists(self, query=None, output='json'): logger.debug("%s (%s)\tlist_artists(query=%s, output=%s)\tHeaders: %s" % (utils.find_originating_host(cherrypy.request.headers), cherrypy.request.login, query, output, cherrypy.request.headers)) artists = self.library.artists(query) if output == 'json': cherrypy.response.headers['Content-Type'] = 'application/json' return json.dumps({'artists': artists}) elif output == 'html': template = Template(file=os.path.join(cfg['THEME_DIR'], 'list_artists.tmpl')) template.artists = artists return template.respond() else: raise cherrypy.HTTPError(501,'Not Implemented')
def list_artists(self, query=None, output='json'): result = {} if query: for song in self.songs: if query.lower() in self.songs[song]['artist'].lower() and self.songs[song]['artist_hash'] not in result: result[self.songs[song]['artist_hash']] = self.songs[song]['artist'] elif query.lower() in self.songs[song]['album'].lower() and self.songs[song]['artist_hash'] not in result: result[self.songs[song]['artist_hash']] = self.songs[song]['artist'] elif query.lower() in self.songs[song]['title'].lower() and self.songs[song]['artist_hash'] not in result: result[self.songs[song]['artist_hash']] = self.songs[song]['artist'] if output == 'json': if result: return str(result) else: return str(self.artists) template = Template(file=os.path.join(self._path, 'templates/list_artists.tmpl')) if result: template.artists = result else: template.artists = self.artists return template.respond()
#fetch_listener_stats(artists, network) pass except httplib.BadStatusLine: print "retrying" while True: try: fetch_listener_stats(artists, network, True) except: print "-> retrying" continue break save_stats(artists, "stats.bin") normalize_stats(artists) write_html(genres) # Test template = Template(file="all.tmpl") template.genres = genres template.artists = artists out = open("html/all.html", "w") out.write(str(template)) out.close() #tag_all(songs, network, subdir=SUB_DIRECTORY, translate=TRANSLATE_TAGS, whitelist=TAG_WHITELIST, min_weight=TAG_MIN_WEIGHT)