added random sample, changed to f strings

This commit is contained in:
aj 2019-07-09 11:01:32 +01:00
parent a27280f5c6
commit 5aa8e47ddf
5 changed files with 25 additions and 8 deletions

View File

@ -121,10 +121,10 @@ def go():
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: config json not found"})
log.dump_log()
except:
log.log("exception occured")
except Exception as e:
log.log("exception occured", e)
if 'SLACKHOOK' in os.environ:
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: exception occured"})
requests.post(os.environ['SLACKHOOK'], json={"text": f"spot playlists: exception occured {e}"})
log.dump_log()

View File

@ -5,7 +5,7 @@ import datetime
class AddedBefore(AbstractProcessor):
def __init__(self, boundary, names=[]):
self.playlist_names = names
super().__init__(names)
self.boundary = boundary
def check_date(self, track):

View File

@ -5,7 +5,7 @@ import datetime
class AddedSince(AbstractProcessor):
def __init__(self, boundary, names=[]):
self.playlist_names = names
super().__init__(names)
self.boundary = boundary
def check_date(self, track):

View File

@ -0,0 +1,17 @@
from .abstractprocessor import AbstractProcessor
import random
class RandomSample(AbstractProcessor):
def __init__(self, sample_size, names=[]):
super().__init__(names)
self.sample_size = sample_size
def process(self, tracks):
return_tracks = list(tracks)
random.shuffle(return_tracks)
return return_tracks[:self.sample_size]

View File

@ -20,7 +20,7 @@ class PlaylistEngine:
self.playlists += self.net.get_user_playlists()
def get_playlist_tracks(self, playlist):
log.log("pulling tracks for {}".format(playlist.name))
log.log(f"pulling tracks for {playlist.name}")
playlist.tracks = self.net.get_playlist_tracks(playlist.playlistid)
def make_playlist(self, playlist_parts, processors=[]):
@ -44,9 +44,9 @@ class PlaylistEngine:
tracks += [i for i in playlist_tracks if i['is_local'] is False]
else:
log.log("requested playlist {} not found".format(part))
log.log(f"requested playlist {part} not found")
if 'SLACKHOOK' in os.environ:
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: {} not found".format(part)})
requests.post(os.environ['SLACKHOOK'], json={"text": f"spot playlists: {part} not found"})
for processor in [i for i in processors if len(i.playlist_names) <= 0]:
tracks = processor.process(tracks)