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'))
print('Connecting to Twitch') sock = socket.socket() sock.connect((self._config['server'], self._config['port'])) sock.send(f'PASS {self._config["token"]}\n'.encode('utf-8')) sock.send(f'NICK {self._config["nickname"]}\n'.encode('utf-8')) sock.send(f'JOIN {self._config["channel"]}\n'.encode('utf-8')) print('Entering Chat loop') self.running = True while self.running: resp = sock.recv(2048).decode('utf-8') if resp.startswith('PING'): sock.send("PONG :tmi.twitch.tv2 3\n".encode('utf-8')) elif len(resp) > 0 and 'PRIVMSG' in resp: if self.handler is not None: username, message = decode(resp) self.handler.receive(username, message) # sock.send(f'PRIVMSG {self._config["channel"]} :received message\n'.encode('utf-8')) if self.debug_output: print(resp) print('Closing socket') sock.close() if __name__ == '__main__': reader = TwitchReader() reader.handler = TTSHandler() reader.debug_output = True reader.run()
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')