def handle_headlines(self, message):
"""Speak the latest headlines from the selected feed."""
title = message.data['TitleKeyword']
feed = feedparser.parse(self.feeds[title])
items = feed.get('items', [])
# Only read three items
if len(items) > 3:
items = items[:3]
self.cache(title, items)
self._is_reading_headlines = True
self.speak('Here\'s the latest headlines from ' +
message.data['TitleKeyword'])
for i in items:
if not self._is_reading_headlines:
break
logger.info('Headline: ' + i['title'])
self.speak(i['title'])
time.sleep(5)
self._is_reading_headlines = False
评论列表
文章目录