How to use the tekore._model.serialise.Timestamp function in tekore

To help you get started, we’ve selected a few tekore examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github felix-hilden / spotipy / tests / model.py View on Github external
def test_timestamp_formatted_back_to_string(self):
        time_str = '2019-01-01T12:00:00Z'
        t = Timestamp.from_string(time_str)
        assert str(t) == time_str
github felix-hilden / spotipy / tekore / _model / album / full.py View on Github external
def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.album = FullAlbum(**self.album)
github felix-hilden / spotipy / tekore / _model / play_history.py View on Github external
def __post_init__(self):
        self.track = FullTrack(**self.track)
        self.played_at = Timestamp.from_string(self.played_at)

        if self.context is not None:
            self.context = Context(**self.context)
github felix-hilden / spotipy / tekore / _model / playlist.py View on Github external
def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.added_by = PublicUser(**self.added_by)

        if self.video_thumbnail is not None:
            self.video_thumbnail = Image(**self.video_thumbnail)

        if self.track is not None:
            if self.is_local:
                self.track = LocalPlaylistTrack(**self.track)
            else:
                self.track = track_type[self.track['type']](**self.track)
github felix-hilden / spotipy / tekore / _model / track.py View on Github external
self.items = ModelList(SimpleTrack(**t) for t in self.items)


@dataclass(repr=False)
class Tracks(Model):
    """Minimal representation of playlist tracks."""

    href: str
    total: int


@dataclass(repr=False)
class SavedTrack(Model):
    """Track saved to library."""

    added_at: Timestamp
    track: FullTrack

    def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.track = FullTrack(**self.track)


@dataclass(repr=False)
class SavedTrackPaging(OffsetPaging):
    """Paging of tracks in library."""

    items: List[SavedTrack]

    def __post_init__(self):
        self.items = ModelList(SavedTrack(**t) for t in self.items)
github felix-hilden / spotipy / tekore / _model / serialise.py View on Github external
def default(self, o):
        """Convert into serialisable data types."""
        if isinstance(o, (Enum, Timestamp)):
            return str(o)
        elif isinstance(o, Model):
            return asdict(o)
        else:
            return super().default(o)
github felix-hilden / spotipy / tekore / _model / album / full.py View on Github external
is_playable: True = None

    def __post_init__(self):
        super().__post_init__()
        if self.available_markets is not None:
            self.available_markets = ModelList(self.available_markets)
        self.copyrights = ModelList(Copyright(**c) for c in self.copyrights)
        self.genres = ModelList(self.genres)
        self.tracks = SimpleTrackPaging(**self.tracks)


@dataclass(repr=False)
class SavedAlbum(Model):
    """Album saved to library."""

    added_at: Timestamp
    album: FullAlbum

    def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.album = FullAlbum(**self.album)


@dataclass(repr=False)
class SavedAlbumPaging(OffsetPaging):
    """Paging of albums in library."""

    items: List[SavedAlbum]

    def __post_init__(self):
        self.items = ModelList(SavedAlbum(**a) for a in self.items)
github felix-hilden / spotipy / tekore / _model / playlist.py View on Github external
episode: bool = False
    track: bool = True


track_type = {
    'track': FullPlaylistTrack,
    'episode': FullPlaylistEpisode,
}


@dataclass(repr=False)
class PlaylistTrack(Model):
    """Track or episode on a playlist."""

    added_at: Timestamp
    added_by: PublicUser
    is_local: bool
    primary_color: str
    video_thumbnail: Optional[Image]
    track: Union[FullPlaylistTrack, LocalPlaylistTrack, FullPlaylistEpisode, None]

    def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.added_by = PublicUser(**self.added_by)

        if self.video_thumbnail is not None:
            self.video_thumbnail = Image(**self.video_thumbnail)

        if self.track is not None:
            if self.is_local:
                self.track = LocalPlaylistTrack(**self.track)
github felix-hilden / spotipy / tekore / _model / play_history.py View on Github external
from .track import FullTrack
from .paging import CursorPaging, Cursor
from .context import Context
from .serialise import Model, ModelList, Timestamp


@dataclass(repr=False)
class PlayHistory(Model):
    """
    Previously played track.

    Context is supposedly sometimes available.
    """

    track: FullTrack
    played_at: Timestamp
    context: Optional[Context]

    def __post_init__(self):
        self.track = FullTrack(**self.track)
        self.played_at = Timestamp.from_string(self.played_at)

        if self.context is not None:
            self.context = Context(**self.context)


@dataclass(repr=False)
class PlayHistoryCursor(Cursor):
    """Cursor to play history."""

    before: str
github felix-hilden / spotipy / tekore / _model / show / __init__.py View on Github external
@dataclass(repr=False)
class SimpleShowPaging(OffsetPaging):
    """Paging of simplified shows."""

    items: List[SimpleShow]

    def __post_init__(self):
        self.items = ModelList(SimpleShow(**i) for i in self.items)


@dataclass(repr=False)
class SavedShow(Model):
    """Show saved in library."""

    added_at: Timestamp
    show: SimpleShow

    def __post_init__(self):
        self.added_at = Timestamp.from_string(self.added_at)
        self.show = SimpleShow(**self.show)


@dataclass(repr=False)
class SavedShowPaging(OffsetPaging):
    """Paging of shows in library."""

    items: List[SavedShow]

    def __post_init__(self):
        self.items = ModelList(SavedShow(**i) for i in self.items)