From 1a2970bc5ddf3ff3e803f82e3db68de6b0344bf0 Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 7 Jan 2020 12:41:40 +0000 Subject: [PATCH] fixed str method checking existence of child objects --- spotframework/listener/cmd.py | 4 +++- spotframework/model/album.py | 2 +- spotframework/model/track.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spotframework/listener/cmd.py b/spotframework/listener/cmd.py index 4d44c4d..067c8e1 100644 --- a/spotframework/listener/cmd.py +++ b/spotframework/listener/cmd.py @@ -3,6 +3,7 @@ import functools import logging from typing import Optional +from spotframework.util.console import Color from spotframework.net.network import Network from spotframework.listener.thread import ListenerThread @@ -75,7 +76,8 @@ class ListenCmd(Cmd): :param tracks: list of target track objects :return: None """ - [print(f'({i.played_at.strftime(self.dt_format)}) {i.name} / {i.artists_names}') + [print(f'({i.played_at.strftime(self.dt_format)}) {Color.BOLD}{Color.RED}{i.name}{Color.END} / ' + f'{i.album.name} / {Color.BOLD}{Color.BLUE}{i.artists_names}{Color.END}') for i in tracks] def print(self): diff --git a/spotframework/model/album.py b/spotframework/model/album.py index 577b387..7e2db64 100644 --- a/spotframework/model/album.py +++ b/spotframework/model/album.py @@ -27,7 +27,7 @@ class Album: return ', '.join(string_list) def __str__(self): - artists = ', '.join([i.name for i in self.artists]) if self.artists else 'n/a' + artists = ', '.join([i.name for i in self.artists]) if self.artists is not None else 'n/a' return f'{self.name} / {artists}' diff --git a/spotframework/model/track.py b/spotframework/model/track.py index cd35854..2ed027f 100644 --- a/spotframework/model/track.py +++ b/spotframework/model/track.py @@ -44,8 +44,8 @@ class Track: return ', '.join(string_list) def __str__(self): - album = self.album.name if self.album else 'n/a' - artists = ', '.join([i.name for i in self.artists]) if self.artists else 'n/a' + album = self.album.name if self.album is not None else 'n/a' + artists = ', '.join([i.name for i in self.artists]) if self.artists is not None else 'n/a' return f'{self.name} / {album} / {artists}'