Skip to content
Snippets Groups Projects
Commit 718a29a4 authored by David Trattnig's avatar David Trattnig
Browse files

Populate "timeslot_id" by default. #50

parent 1adfdcd3
No related branches found
No related tags found
No related merge requests found
......@@ -121,7 +121,7 @@ class CalendarFetcher:
Returns:
([Timeslot]): An array of timeslots
"""
timeslot = None
timeslots = None
headers = { "content-type": "application/json" }
try:
......@@ -131,15 +131,15 @@ class CalendarFetcher:
self.logger.critical(SU.red("HTTP Status: %s | Timeslots could not be fetched! Response: %s" % \
(str(response.status_code), response.text)))
return None
timeslot = response.json()
timeslots = response.json()
except Exception as e:
self.logger.critical(SU.red("Error while requesting timeslots from Steering!"), e)
if not timeslot:
self.logger.error(SU.red("Got no timeslot via Playout API (Steering)!"))
if not timeslots:
self.logger.error(SU.red("Got no timeslots via Playout API (Steering)!"))
return None
return self.remove_unnecessary_data(timeslot)
return self.polish_timeslots(timeslots)
......@@ -222,24 +222,27 @@ class CalendarFetcher:
"""
playlist_id = str(timeslot[id_name])
if not playlist_id or playlist_id == "None":
self.logger.debug("No value defined for '%s' in timeslot '#%s'" % (id_name, timeslot["timeslot_id"]))
self.logger.debug("No value defined for '%s' in timeslot '#%s'" % (id_name, timeslot["id"]))
return None
return playlist_id
def remove_unnecessary_data(self, timeslot):
def polish_timeslots(self, timeslots):
"""
Removes all timeslots which are not relevant for
further processing.
Removes all timeslots which are not relevant for further processing,
and transparent timeslot ID assigment for more expressive use.
"""
count_before = len(timeslot)
timeslot = self.remove_data_more_than_24h_in_the_future(timeslot)
timeslot = self.remove_data_in_the_past(timeslot)
count_after = len(timeslot)
count_before = len(timeslots)
timeslots = self.remove_data_more_than_24h_in_the_future(timeslots)
timeslots = self.remove_data_in_the_past(timeslots)
count_after = len(timeslots)
self.logger.debug("Removed %d unnecessary timeslots from response. Timeslots left: %d" % ((count_before - count_after), count_after))
for t in timeslots:
t["timeslot_id"] = t["id"]
return timeslots
self.logger.debug("Removed %d unnecessary timeslots from response. Entries left: %d" % ((count_before - count_after), count_after))
return timeslot
def remove_data_more_than_24h_in_the_future(self, timeslots):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment