class NewsReader(object): """ Object that represnets the news reader. Uses feedparser to fetch the news and then uses eSpeak to speak out the news """ def __init__(self, rssList=[]): """ The ctor for this object. This takes in list of RSS feeds """ self.rss = rssList self.rssLen = len(rssList) self.speaker = TTSHandler('espeak') def setRssLinks(self, rssList): """ Sets the current RSS list to the given list """ self.rss = rssList self.rssLen = len(self.rss) def run(self): """ When called, picks one of the RSS links randomly and then reads out the news """ print self.rssLen link = self.rss[randint(0, self.rssLen - 1)] print "Selected link is %s" % link msgToSpeak = "" try: feed = fp.parse(link) except: msgToSpeak = "Could not fetch the RSS feed, please try again" try: msgToSpeak = feed['entries'][0]['title_detail'][ 'value'] # Speak top headline except: msgToSpeak = "Could not get the right value" print "The message that I got" print msgToSpeak self.speaker.speak(msgToSpeak.encode('ASCII'))
class NewsReader(object): """ Object that represnets the news reader. Uses feedparser to fetch the news and then uses eSpeak to speak out the news """ def __init__(self, rssList=[]): """ The ctor for this object. This takes in list of RSS feeds """ self.rss = rssList self.rssLen = len(rssList) self.speaker = TTSHandler('espeak') def setRssLinks(self, rssList): """ Sets the current RSS list to the given list """ self.rss = rssList; self.rssLen = len(self.rss) def run(self): """ When called, picks one of the RSS links randomly and then reads out the news """ print self.rssLen link = self.rss[randint(0, self.rssLen-1)] print "Selected link is %s" %link msgToSpeak = "" try: feed = fp.parse(link) except: msgToSpeak = "Could not fetch the RSS feed, please try again" try: msgToSpeak = feed['entries'][0]['title_detail']['value'] # Speak top headline except: msgToSpeak = "Could not get the right value" print "The message that I got" print msgToSpeak self.speaker.speak(msgToSpeak.encode('ASCII'))