diff --git a/src/scheduling/calender_fetcher.py b/src/scheduling/calender_fetcher.py index e227d3d2e0e4741899b29c75a328c5edee86c1dd..1fd41a04492c7e185f557b7d7fcf73257dc00250 100644 --- a/src/scheduling/calender_fetcher.py +++ b/src/scheduling/calender_fetcher.py @@ -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):