Skip to content
Snippets Groups Projects
Commit 9fe9fc7f authored by Gottfried Gaisbauer's avatar Gottfried Gaisbauer
Browse files

improved output in case of error

parent 24ef6b75
No related branches found
No related tags found
No related merge requests found
......@@ -43,8 +43,9 @@ class AuraCalendarService(threading.Thread):
self.messenger.set_channel("aura")
self.messenger.set_section("calendar")
self.dateto = dateto
self.datefrom = str(datefrom)
self.dateto = dateto
self.queue = queue.Queue()
self._stop_event = threading.Event()
......@@ -121,10 +122,11 @@ class AuraCalendarService(threading.Thread):
schedule_db = self.store_schedule(schedule)
# store playlists to play
self.store_schedule_playlist(schedule_db, schedule["playlist"])
self.store_schedule_playlist(schedule_db, schedule["schedule_fallback"], True)
self.store_schedule_playlist(schedule_db, schedule["show_fallback"], True)
self.store_schedule_playlist(schedule_db, schedule["station_fallback"], True)
self.store_schedule_playlist(schedule_db, schedule, "playlist")
self.store_schedule_playlist(schedule_db, schedule, "schedule_fallback", True)
self.store_schedule_playlist(schedule_db, schedule, "show_fallback", True)
self.store_schedule_playlist(schedule_db, schedule, "station_fallback", True)
# release the mutex
self.queue.put(schedule) #"fetching_finished")
......@@ -171,16 +173,25 @@ class AuraCalendarService(threading.Thread):
return schedule_db
# ------------------------------------------------------------------------------------------ #
def store_schedule_playlist(self, schedule_db, playlist, isfallbackplaylist=False):
def store_schedule_playlist(self, schedule_db, schedule, playlistname, isfallbackplaylist=False):
playlist = schedule[playlistname]
info = "Trying to store schedule playlist (" + playlistname + ") for " + schedule_db.show_name
warning = "No scheduleentries for playlist #" + str(playlist['playlist_id']) + " in schedule #" + str(schedule_db.schedule_id) + " found"
entrynum = 0
self.logger.info(info)
if "entries" in playlist:
lastentry = None
for entry in playlist["entries"]:
lastentry = self.store_playlist_entry(schedule_db, playlist, entry, lastentry, entrynum, isfallbackplaylist)
entrynum = entrynum + 1
if lastentry is None:
self.logger.warning(warning)
else:
self.logger.warning("No scheduleentries for playlist #" + str(playlist['playlist_id']) + " in schedule #" + str(schedule_db.schedule_id) + " found")
self.logger.warning(warning)
# ------------------------------------------------------------------------------------------ #
def store_playlist_entry(self, schedule_db, playlist, entry, lastentry, entrynum, isfallbackplaylist=False):
......@@ -267,6 +278,7 @@ class AuraCalendarService(threading.Thread):
json_response = self.__fetch_data__(servicetype)
if not json_response:
self.logger.info("Using hardcoded playlists")
use_testdata = True
for entry in fetched_schedule_entries:
......@@ -330,6 +342,9 @@ class AuraCalendarService(threading.Thread):
# ------------------------------------------------------------------------------------------ #
def __fetch_data__(self, type):
# init html_response
html_response = ""
# open an url and read the data
try:
if type not in self.data:
......@@ -343,7 +358,7 @@ class AuraCalendarService(threading.Thread):
html_response = response.read()
except (urllib.error.URLError, IOError, ValueError) as e:
self.logger.error("Cannot connect to " + self.config.get("calendarurl") + "! reason: " + str(e.reason))
self.logger.error("Cannot connect to " + self.url[type] + "! reason: " + str(e.reason))
if not self.has_already_fetched: # first fetch
sys.exit()
......
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