Commit 96bfc486 authored by David Trattnig's avatar David Trattnig
Browse files

Reuse timeslots which got just stored. #41

parent 51cc9001
......@@ -70,17 +70,13 @@ class ProgrammeService():
response = self.api_fetcher.get_fetched_data()
# Reset last successful fetch state
lsf = self.last_successful_fetch
self.last_successful_fetch = None
if response is None:
msg ="Trying to load programme from Engine Database, because ApiFetcher returned an empty response.")
elif type(response) is list:
if len(response) > 0:
self.last_successful_fetch =
self.timeslots = self.programme_store.store_timeslots(response)"Finished fetching current programme from API ({len(response)} timeslots)"))
self.logger.critical("Programme fetched from Steering/Tank has no entries!")
......@@ -91,10 +87,11 @@ class ProgrammeService():
msg ="Load programme from DB, because of an unknown response from ApiFetcher: " + response)
# Always load latest programme from the database
self.last_successful_fetch = lsf
self.timeslots = self.programme_store.load_timeslots()"Finished loading current programme from database (%s timeslots)" % str(len(self.timeslots))))
# Load latest programme from the database
if not self.timeslots:
self.timeslots = self.programme_store.load_timeslots()"Finished loading current programme from database (%s timeslots)" % str(len(self.timeslots))))
for timeslot in self.timeslots:
self.logger.debug("\tTimeslot %s with Playlist %s" % (str(timeslot), str(timeslot.playlist)))
......@@ -186,7 +183,7 @@ class ProgrammeService():
return self.filter_scheduling_window(next_timeslots)
......@@ -268,10 +265,13 @@ class ProgrammeStore():
return timeslots
def store_timeslots(self, fetched_timeslots):
Stores the fetched timeslots to the database.
timeslots = []
# Check if existing timeslots have been deleted
......@@ -288,15 +288,18 @@ class ProgrammeStore():
# Store the timeslot
timeslot_db = self.store_timeslot(timeslot)
# Store playlists to play
# Store assigned playlists
self.store_playlist(timeslot_db, timeslot_db.playlist_id, timeslot["playlist"])
if timeslot_db.schedule_fallback_id:
self.store_playlist(timeslot_db, timeslot_db.schedule_fallback_id, timeslot["schedule_fallback"])
if timeslot_db.show_fallback_id:
self.store_playlist(timeslot_db, timeslot_db.show_fallback_id, timeslot["show_fallback"])
if timeslot_db.station_fallback_id:
self.store_playlist(timeslot_db, timeslot_db.station_fallback_id, timeslot["station_fallback"])
self.store_playlist(timeslot_db, timeslot_db.station_fallback_id, timeslot["station_fallback"])
return timeslots
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment