def load(): for sid in config.station_ids: current[sid] = cache.get_station(sid, "sched_current") # If our cache is empty, pull from the DB if not current[sid]: current[sid] = get_event_in_progress(sid) if not current[sid]: raise Exception("Could not load any events!") upnext[sid] = cache.get_station(sid, "sched_next") if not upnext[sid]: upnext[sid] = [] manage_next(sid) history[sid] = cache.get_station(sid, "sched_history") if not history[sid]: history[sid] = [] for song_id in db.c.fetch_list( "SELECT song_id FROM r4_song_history JOIN r4_song_sid USING (song_id, sid) JOIN r4_songs USING (song_id) WHERE sid = %s AND song_exists = TRUE AND song_verified = TRUE ORDER BY songhist_time DESC LIMIT 5", (sid,), ): history[sid].insert(0, events.singlesong.SingleSong(song_id, sid)) # create a fake history in case clients expect it without checking if not len(history[sid]): for i in range(1, 5): history[sid].insert(0, events.singlesong.SingleSong(playlist.get_random_song_ignore_all(sid), sid))
def load(): for sid in config.station_ids: current[sid] = cache.get_station(sid, "sched_current") # If our cache is empty, pull from the DB if not current[sid]: current[sid] = get_event_in_progress(sid) if not current[sid]: raise Exception("Could not load any events!") upnext[sid] = cache.get_station(sid, "sched_next") if not upnext[sid]: upnext[sid] = [] manage_next(sid) history[sid] = cache.get_station(sid, "sched_history") if not history[sid]: history[sid] = [] for song_id in db.c.fetch_list( "SELECT song_id FROM r4_song_history JOIN r4_song_sid USING (song_id, sid) JOIN r4_songs USING (song_id) WHERE sid = %s AND song_exists = TRUE AND song_verified = TRUE ORDER BY songhist_time DESC LIMIT 5", (sid,), ): history[sid].insert(0, events.singlesong.SingleSong(song_id, sid)) # create a fake history in case clients expect it without checking if not history[sid]: for i in range(1, 5): history[sid].insert( 0, events.singlesong.SingleSong( playlist.get_random_song_ignore_all(sid), sid ), )
def test_random_select(self): playlist.Song.load_from_file("tests/test1.mp3", [1]) self.assertNotEqual(None, playlist.get_random_song_timed(1, 1)) self.assertNotEqual(None, playlist.get_random_song(1)) self.assertNotEqual(None, playlist.get_random_song_ignore_requests(1)) self.assertNotEqual(None, playlist.get_random_song_ignore_all(1))