added random sample, changed to f strings
This commit is contained in:
parent
a27280f5c6
commit
5aa8e47ddf
@ -121,10 +121,10 @@ def go():
|
|||||||
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: config json not found"})
|
requests.post(os.environ['SLACKHOOK'], json={"text": "spot playlists: config json not found"})
|
||||||
|
|
||||||
log.dump_log()
|
log.dump_log()
|
||||||
except:
|
except Exception as e:
|
||||||
log.log("exception occured")
|
log.log("exception occured", e)
|
||||||
if 'SLACKHOOK' in os.environ:
|
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()
|
log.dump_log()
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import datetime
|
|||||||
class AddedBefore(AbstractProcessor):
|
class AddedBefore(AbstractProcessor):
|
||||||
|
|
||||||
def __init__(self, boundary, names=[]):
|
def __init__(self, boundary, names=[]):
|
||||||
self.playlist_names = names
|
super().__init__(names)
|
||||||
self.boundary = boundary
|
self.boundary = boundary
|
||||||
|
|
||||||
def check_date(self, track):
|
def check_date(self, track):
|
||||||
|
@ -5,7 +5,7 @@ import datetime
|
|||||||
class AddedSince(AbstractProcessor):
|
class AddedSince(AbstractProcessor):
|
||||||
|
|
||||||
def __init__(self, boundary, names=[]):
|
def __init__(self, boundary, names=[]):
|
||||||
self.playlist_names = names
|
super().__init__(names)
|
||||||
self.boundary = boundary
|
self.boundary = boundary
|
||||||
|
|
||||||
def check_date(self, track):
|
def check_date(self, track):
|
||||||
|
17
spotframework/engine/filter/randomsample.py
Normal file
17
spotframework/engine/filter/randomsample.py
Normal 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]
|
@ -20,7 +20,7 @@ class PlaylistEngine:
|
|||||||
self.playlists += self.net.get_user_playlists()
|
self.playlists += self.net.get_user_playlists()
|
||||||
|
|
||||||
def get_playlist_tracks(self, playlist):
|
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)
|
playlist.tracks = self.net.get_playlist_tracks(playlist.playlistid)
|
||||||
|
|
||||||
def make_playlist(self, playlist_parts, processors=[]):
|
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]
|
tracks += [i for i in playlist_tracks if i['is_local'] is False]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.log("requested playlist {} not found".format(part))
|
log.log(f"requested playlist {part} not found")
|
||||||
if 'SLACKHOOK' in os.environ:
|
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]:
|
for processor in [i for i in processors if len(i.playlist_names) <= 0]:
|
||||||
tracks = processor.process(tracks)
|
tracks = processor.process(tracks)
|
||||||
|
Loading…
Reference in New Issue
Block a user