Skip to content

Commit

Permalink
reddit: cath and log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
setrofim committed May 5, 2016
1 parent 4ee9dba commit ded23c3
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions billboard/sources/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def get_image(self, path):
self._seen.add(url)
except StopIteration:
if self._seen:
self.logger.debug('Did not find a suitable image; re-using one seen before.')
return random.choice(self._seen)
num_seen = len(self._seen)
msg = 'Did not find a suitable image; reusing one of {} seen before.'
self.logger.debug(msg.format(num_seen))
url = random.choice(self._seen)
else:
self.logger.debug('Could not find any suitable images :(')
return None
Expand Down Expand Up @@ -110,9 +112,16 @@ def __init__(self):
self.logger = logging.getLogger('reddit')

def next(self):
if not self.imagegetter.get_image(self.image_path):
self.logger.error("Did not find a suitable image.")
text = self.textgetter.get_text()
if not text:
self.logger.error("Did not find a suitable text.")
try:
if not self.imagegetter.get_image(self.image_path):
self.logger.error("Did not find a suitable image.")
except Exception as e:
self.logger.error(e)
try:
text = self.textgetter.get_text()
if not text:
self.logger.error("Did not find a suitable text.")
except Exception as e:
text = None
self.logger.error(e)
return self.image_path, text

0 comments on commit ded23c3

Please sign in to comment.