def get(self): recent_songs = cache.getLastPlays(num=3) logging.debug(recent_songs) if recent_songs is not None and len(recent_songs) > 0: last_play = recent_songs[0] song, program = (cache.getSong(last_play.song_key), cache.getProgram(last_play.program_key)) song_string = song.title + " — " + song.artist program_title, program_desc, program_slug = (program.title, program.desc, program.slug) else: song, program = None, None song_string = "Nothing is playing" program_title, program_desc, program_slug = ("No show", "No description", "") self.response.headers["Content-Type"] = "text/json" self.response.out.write( json.dumps({ 'song_string': song_string, 'program_title': program_title, 'program_desc': program_desc, 'program_slug': program_slug, 'top_played': ("Top artists: " + ", ".join([a for a in program.top_artists[:3]]) if program is not None else None), 'recent_songs_html': template.render(getPath("recent_songs.html"), {'plays': recent_songs}), }))
def get(self): recent_songs = cache.getLastPlays(num=3) logging.debug(recent_songs) if recent_songs is not None and len(recent_songs) > 0: last_play = recent_songs[0] song, program = (cache.getSong(last_play.song_key), cache.getProgram(last_play.program_key)) song_string = song.title + " — " + song.artist program_title, program_desc, program_slug = (program.title, program.desc, program.slug) else: song, program = None, None song_string = "Nothing is playing" program_title, program_desc, program_slug = ("No show", "No description", "") self.response.headers["Content-Type"] = "text/json" self.response.out.write( json.dumps( { "song_string": song_string, "program_title": program_title, "program_desc": program_desc, "program_slug": program_slug, "top_played": ( "Top artists: " + ", ".join([a for a in program.top_artists[:3]]) if program is not None else None ), "recent_songs_html": template.render(getPath("recent_songs.html"), {"plays": recent_songs}), } ) )
def get(self, key): program = cache.getProgram(key) if program: self.json_respond(program.to_json())