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: ...@@ -121,7 +121,7 @@ class CalendarFetcher:
Returns: Returns:
([Timeslot]): An array of timeslots ([Timeslot]): An array of timeslots
""" """
timeslot = None timeslots = None
headers = { "content-type": "application/json" } headers = { "content-type": "application/json" }
try: try:
...@@ -131,15 +131,15 @@ class CalendarFetcher: ...@@ -131,15 +131,15 @@ class CalendarFetcher:
self.logger.critical(SU.red("HTTP Status: %s | Timeslots could not be fetched! Response: %s" % \ self.logger.critical(SU.red("HTTP Status: %s | Timeslots could not be fetched! Response: %s" % \
(str(response.status_code), response.text))) (str(response.status_code), response.text)))
return None return None
timeslot = response.json() timeslots = response.json()
except Exception as e: except Exception as e:
self.logger.critical(SU.red("Error while requesting timeslots from Steering!"), e) self.logger.critical(SU.red("Error while requesting timeslots from Steering!"), e)
if not timeslot: if not timeslots:
self.logger.error(SU.red("Got no timeslot via Playout API (Steering)!")) self.logger.error(SU.red("Got no timeslots via Playout API (Steering)!"))
return None return None
return self.remove_unnecessary_data(timeslot) return self.polish_timeslots(timeslots)
...@@ -222,24 +222,27 @@ class CalendarFetcher: ...@@ -222,24 +222,27 @@ class CalendarFetcher:
""" """
playlist_id = str(timeslot[id_name]) playlist_id = str(timeslot[id_name])
if not playlist_id or playlist_id == "None": 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 None
return playlist_id return playlist_id
def remove_unnecessary_data(self, timeslot): def polish_timeslots(self, timeslots):
""" """
Removes all timeslots which are not relevant for Removes all timeslots which are not relevant for further processing,
further processing. and transparent timeslot ID assigment for more expressive use.
""" """
count_before = len(timeslot) count_before = len(timeslots)
timeslot = self.remove_data_more_than_24h_in_the_future(timeslot) timeslots = self.remove_data_more_than_24h_in_the_future(timeslots)
timeslot = self.remove_data_in_the_past(timeslot) timeslots = self.remove_data_in_the_past(timeslots)
count_after = len(timeslot) 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): 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