From f4c48bd577e3d6f23abdc3369ad6bbf478db3747 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Wed, 19 Feb 2020 14:47:18 +0100 Subject: [PATCH] Added convenience methods. --- libraries/database/broadcasts.py | 53 ++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/libraries/database/broadcasts.py b/libraries/database/broadcasts.py index a93b8d11..03f47cab 100644 --- a/libraries/database/broadcasts.py +++ b/libraries/database/broadcasts.py @@ -38,6 +38,8 @@ from sqlalchemy import create_engine from libraries.enum.auraenumerations import ScheduleEntryType from aura import DB +from modules.base.simpleutil import SimpleUtil + class AuraDatabaseModel(): @@ -218,11 +220,31 @@ class Schedule(DB.Model, AuraDatabaseModel): return all_entries + @hybrid_property + def start_unix(self): + """ + Start time of the schedule in UNIX time. + """ + return time.mktime(self.schedule_start.timetuple()) + + + @hybrid_property + def end_unix(self): + """ + End time of the schedule in UNIX time. + """ + return time.mktime(self.schedule_end.timetuple()) + + def __str__(self): """ String representation of the object. """ - return "ID#%s [Show: %s, ShowID: %s]" % (str(self.schedule_id), self.show_name, str(self.show_id)) + time_start = SimpleUtil.fmt_time(self.start_unix) + time_end = SimpleUtil.fmt_time(self.end_unix) + return "ID#%s [Show: %s, ShowID: %s | %s - %s ]" % (str(self.schedule_id), self.show_name, str(self.show_id), time_start, time_end) + + # ------------------------------------------------------------------------------------------ # class Playlist(DB.Model, AuraDatabaseModel): @@ -324,13 +346,12 @@ class Playlist(DB.Model, AuraDatabaseModel): """ String representation of the object. """ - time_start = self.fmt_time(self.start_unix) - time_end = self.fmt_time(self.end_unix) - return "ID#%s [items: %s, start: %s, end: %s]" % (str(self.playlist_id), str(self.entry_count), str(time_start), str(time_end)) + time_start = SimpleUtil.fmt_time(self.start_unix) + time_end = SimpleUtil.fmt_time(self.end_unix) + return "ID#%s [items: %s | %s - %s]" % (str(self.playlist_id), str(self.entry_count), str(time_start), str(time_end)) + - def fmt_time(self, timestamp): - return datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S') # ------------------------------------------------------------------------------------------ # class PlaylistEntry(DB.Model, AuraDatabaseModel): @@ -386,18 +407,30 @@ class PlaylistEntry(DB.Model, AuraDatabaseModel): elif self.cleansource == "4": return ScheduleEntryType.LIVE_4 + def get_next_entries(self): + """ + Retrieves all following entries as part of the current entries playlist. + + Returns: + (List): List of PlaylistEntry + """ + next_entries = [] + for entry in self.playlist.entries: + if entry.entry_start > self.entry_start: + next_entries.append(entry) + return next_entries + def __str__(self): """ String representation of the object. """ - time_start = self.fmt_time(self.start_unix) - time_end = self.fmt_time(self.end_unix) + time_start = SimpleUtil.fmt_time(self.start_unix) + time_end = SimpleUtil.fmt_time(self.end_unix) track = self.filename[-15:] return "PlaylistEntry ID#%s [%s - %s | %ssec | Track: ...%s]" % (str(self.artificial_id), time_start, time_end, self.duration, track) - def fmt_time(self, timestamp): - return datetime.datetime.fromtimestamp(timestamp).strftime('%H:%M:%S') + # ------------------------------------------------------------------------------------------ # class PlaylistEntryMetaData(DB.Model, AuraDatabaseModel): -- GitLab