Skip to content

Commit

Permalink
Merge pull request #828 from MrServo/master
Browse files Browse the repository at this point in the history
[TVSpielfilm] 1.0 improved error interception
  • Loading branch information
jbleyel authored Jan 26, 2025
2 parents 8aae6ea + bffcc57 commit 0369304
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions TVSpielfilm/src/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,13 @@ def imageDownload(self, url, imgfile, callback=None, assetId=""):
except exceptions.RequestException as error:
print("[%s] ERROR in class 'TVglobals:imageDownload': %s" % (tvglobals.MODULE_NAME, str(error)))
return
with open(imgfile, "wb") as file:
file.write(response.content)
if callback:
callback(imgfile, assetId)
try:
with open(imgfile, "wb") as file:
file.write(response.content)
if callback:
callback(imgfile, assetId)
except OSError as error:
self.session.open(MessageBox, "Bild konnte nicht gespeichert werden:\n'%s'" % error, type=MessageBox.TYPE_INFO, timeout=2, close_on_any_key=True)

def saveAllAssets(self, assetsdict, date, spanStarts):
if assetsdict and date:
Expand All @@ -130,7 +133,7 @@ def saveAllAssets(self, assetsdict, date, spanStarts):
with open(assetsfile, "w") as file:
file.write(dumps(assetsdict))
except OSError as error:
self.session.open(MessageBox, "Datensatz konnte nicht gespeichert werden:\n'%s'" % error, type=MessageBox.TYPE_INFO, timeout=2, close_on_any_key=True)
self.session.open(MessageBox, "Datensatz 'Sendungsdetails' konnte nicht gespeichert werden:\n'%s'" % error, type=MessageBox.TYPE_INFO, timeout=2, close_on_any_key=True)
return False
return True

Expand All @@ -153,8 +156,12 @@ def showAssetDetails(self, assetId, fullscreen=False): # e.g. 'ARD672261f960673
print(f"[{tvglobals.MODULE_NAME}] ERROR in class 'TVoverview:showAssetDetails': {errmsg}!")
return
assetdict = jsondict.get("asset", {})
with open(assetfile, "w") as file: # save details for current asset to cache
file.write(dumps(assetdict))
try:
with open(assetfile, "w") as file: # save details for current asset to cache
file.write(dumps(assetdict))
except OSError as error:
self.session.open(MessageBox, "Datensatz 'Sendungsdetails' konnte nicht gespeichert werden:\n'%s'" % error, type=MessageBox.TYPE_INFO, timeout=2, close_on_any_key=True)

if assetdict:
isTopTip = assetdict.get("flags", {}).get("isTopTip", "")
isTipOfTheDay = assetdict.get("flags", {}).get("isTipOfTheDay", "")
Expand Down Expand Up @@ -387,8 +394,11 @@ def getTips(self, callback):
if errmsg:
print(f"[{tvglobals.MODULE_NAME}] ERROR in class 'TVmain:getTips': {errmsg}!")
return
with open(tipsfile, "w") as file:
file.write(dumps(tipsdict))
try:
with open(tipsfile, "w") as file:
file.write(dumps(tipsdict))
except OSError as error:
self.session.open(MessageBox, "Datensatz 'Tipps' konnte nicht gespeichert werden:\n'%s'" % error, type=MessageBox.TYPE_INFO, timeout=2, close_on_any_key=True)
tipslist = []
for index, tips in enumerate([[tipsdict.get("topTip", {})], tipsdict.get("tips", {}), tipsdict.get("highlights", {}),]):
for tip in tips:
Expand Down

0 comments on commit 0369304

Please sign in to comment.