def _start_(self, **kwargs): """ Setups the file to be read. FileReader does the heavy lifting. * Get the YomboBot, and register the log reader as a user, even though it's blank. * Use the FileReader to open the file and monitor it for new lines. * Send any lines of text from the file reader to the YomboBot. """ # Register with YomboBot. self.YomboBot.registerConnection(source=self, sessionid='logreader', authuser="******", remoteuser='******') # Setup the FileReader and tell it to send new text to "newContent()" try: self.fileReader = FileReader(self, filename=self.fileName, callback=self.newContent) self.fileReader.start() self.isRunning = True except YomboFileError as e: self.fileReader = None logger.warn("Error with FileReader: %s" % e)
class LogReader(YomboModule): """ Monitors a file for voice commands and send them to yombobot for processing. :ivar fileReader: A yombo :doc:`FileReader <../core/filereader>` that reads text files delivers lines of text to callable. """ def _init_(self): """ Init the module. """ self._ModDescription = "Logread monitors a file for voice commands." self._ModAuthor = "Mitch Schwenk @ Yombo" self._ModUrl = "https://yombo.net" self.fileReader = None # Used to test if file reader is running on stop. def _load_(self): # Make sure YomboBot is loaded and available. try: self.YomboBot = self._Modules['yombobot'] except: logger.warn("Logreader module can't start due to no YomboBot module loaded.") return # Get a file name to monitor. if "logfile" in self._ModuleVariables: self.fileName = self._ModuleVariables["logfile"][0]['value'] else: logger.warn("No 'logfile' set for logreader, using default: 'logreader.txt'") self.fileName = "logreader.txt" def _start_(self): """ Setups the file to be read. FileReader does the heavy lifting. * Get the YomboBot, and register the log reader as a user, even though it's blank. * Use the FileReader to open the file and monitor it for new lines. * Send any lines of text from the file reader to the YomboBot. """ # Register with YomboBot. self.YomboBot.registerConnection(source=self, sessionid='logreader', authuser="******", remoteuser='******') # Setup the FileReader and tell it to send new text to "newContent()" try: self.fileReader = FileReader(self, filename=self.fileName, callback=self.newContent) self.fileReader.start() self.isRunning = True except YomboFileError, e: self.fileReader = None logger.warn("Error with FileReader: %s" % e)
def _start_(self): """ Setups the file to be read. FileReader does the heavy lifting. * Get the YomboBot, and register the log reader as a user, even though it's blank. * Use the FileReader to open the file and monitor it for new lines. * Send any lines of text from the file reader to the YomboBot. """ # Register with YomboBot. self.YomboBot.registerConnection(source=self, sessionid='logreader', authuser="******", remoteuser='******') # Setup the FileReader and tell it to send new text to "newContent()" try: self.fileReader = FileReader(self, filename=self.fileName, callback=self.newContent) self.fileReader.start() self.isRunning = True except YomboFileError, e: self.fileReader = None logger.warn("Error with FileReader: %s" % e)
class LogReader(YomboModule): """ Monitors a file for voice commands and send them to yombobot for processing. :ivar fileReader: A yombo :doc:`FileReader <../utils/filereader>` that reads text files delivers lines of text to callable. """ def _init_(self, **kwargs): """ Init the module. """ self.fileReader = None # Used to test if file reader is running on stop. def _load_(self, **kwargs): # Make sure YomboBot is loaded and available. try: self.YomboBot = self._Modules['yombobot'] except: logger.warn( "Logreader module can't start due to no YomboBot module loaded." ) return # Get a file name to monitor. if "logfile" in self._module_variables_cached: self.fileName = self._module_variables_cached["logfile"][0][ 'value'] else: logger.warn( "No 'logfile' set for logreader, using default: 'logreader.txt'" ) self.fileName = "logreader.txt" def _start_(self, **kwargs): """ Setups the file to be read. FileReader does the heavy lifting. * Get the YomboBot, and register the log reader as a user, even though it's blank. * Use the FileReader to open the file and monitor it for new lines. * Send any lines of text from the file reader to the YomboBot. """ # Register with YomboBot. self.YomboBot.registerConnection(source=self, sessionid='logreader', authuser="******", remoteuser='******') # Setup the FileReader and tell it to send new text to "newContent()" try: self.fileReader = FileReader(self, filename=self.fileName, callback=self.newContent) self.fileReader.start() self.isRunning = True except YomboFileError as e: self.fileReader = None logger.warn("Error with FileReader: %s" % e) def newContent(self, linein): """ Receives new lines of text from the FileReader here. Just pass the raw string to YomboBot for parsing. """ pass def _stop_(self): """ Module is shutting down. If a FileReader was setup, delete it. FileReader will close the file and save it's current location. This will be used next time as a starting point. """ if self.fileReader is not None: self.fileReader.close() def _unload_(self): """ Nothing to do, move along. """ pass