Exemple #1
0
def run_remind_recurring ():
    '''
        Run Remind Recurring

        Find and send all of the recurring reminders that are due

        --
        @return void
    '''

    logger.debug('Running Remind Recurring Job')

    try:

        # Get reminders have have not been marked as completed, as well as
        # have their next_run date ready or not set
        for reminder in RemindRecurring.select().where(RemindRecurring.sent == 0,
                                                       ((RemindRecurring.next_run <= datetime.now()) | (
                                                           RemindRecurring.next_run >> None))):

            # If we know the next_run date, send the message. If
            # we dont know the next_run, this will be skipped
            # and only the next_run determined
            if reminder.next_run is not None:
                logger.debug('Sending recurring reminder message with id {id}'.format(
                    id = reminder.id
                ))

                # Send the actual reminder
                Telegram.send_message(
                    _get_sender_information(reminder.orig_message),
                    'text',
                    reminder.message)

            # Lets parse the rrules and update the next_run time for
            # a message. We will use python-dateutil to help with
            # determinig the next run based on the parsed RRULE
            # relative from now.
            next_run = rrulestr(reminder.rrules,
                                dtstart = datetime.now()).after(datetime.now())

            # If there is no next run, consider the
            # schedule complete and mark it as
            # sent
            if not next_run:
                reminder.sent = 1
                reminder.save()

                continue

            # Save the next run
            reminder.next_run = next_run
            reminder.save()

    except Exception, e:

        print traceback.format_exc()
    def run_plugins(self):
        '''
            Run Plugins

            This is the main function responsible for executing
            the plugins that have been identified for this
            message.

            --
            @return None
        '''

        if not self.plugins:
            logger.warning('No plugins matched for this message.')
            return

        #TODO: Handle if no plugins are applicable!
        for plugin in self.plugins:

            try:

                logger.info(
                    'Running plugin: {plugin} for message {message_id}'.format(
                        plugin=plugin['name'],
                        message_id=self.response['message_id']))

                # Run the plugins run() method
                plugin_output = plugin['plugin'].run(self.response)

            except Exception, e:

                logger.error(
                    'Plugin {plugin} failed with: {error}: {trace}'.format(
                        plugin=plugin['name'],
                        error=str(e),
                        trace=traceback.print_exc()))
                continue

            # If we should be replying to the message,
            # do it.
            if (plugin['plugin'].should_reply()):

                # Check what the reply type should be. Plugins
                # that don't specify one will default to text
                reply_type = 'text'
                if hasattr(plugin['plugin'], 'reply_type'):
                    reply_type = plugin['plugin'].reply_type()

                Telegram.send_message(self.sender_information, reply_type,
                                      plugin_output)
    def run_plugins(self):

        '''
            Run Plugins

            This is the main function responsible for executing
            the plugins that have been identified for this
            message.

            --
            @return None
        '''

        if not self.plugins:
            logger.warning('No plugins matched for this message.')
            return

        #TODO: Handle if no plugins are applicable!
        for plugin in self.plugins:

            try:

                logger.info('Running plugin: {plugin} for message {message_id}'.format(
                    plugin = plugin['name'],
                    message_id = self.response['message_id']
                ))

                # Run the plugins run() method
                plugin_output = plugin['plugin'].run(self.response)

            except Exception, e:

                logger.error('Plugin {plugin} failed with: {error}: {trace}'.format(
                    plugin = plugin['name'],
                    error = str(e),
                    trace = traceback.print_exc()
                ))
                continue

            # If we should be replying to the message,
            # do it.
            if (plugin['plugin'].should_reply()):

                # Check what the reply type should be. Plugins
                # that don't specify one will default to text
                reply_type = 'text'
                if hasattr(plugin['plugin'], 'reply_type'):
                    reply_type = plugin['plugin'].reply_type()

                Telegram.send_message(self.sender_information, reply_type, plugin_output)
Exemple #4
0
def run_remind_once ():
    '''
        Run Remind Once

        Find and send all of the once time reminders that are due

        --
        @return void
    '''

    logger.debug('Running Remind Once Job')

    try:

        for reminder in RemindOnce.select().where(RemindOnce.sent == 0,
                                                  RemindOnce.time <= datetime.now()):
            logger.debug('Sending one time reminder message with id {id}'.format(
                id = reminder.id
            ))

            # Send the actual reminder
            Telegram.send_message(
                _get_sender_information(reminder.orig_message),
                'text',
                reminder.message
            )

            # Mark it as complete
            reminder.sent = 1
            reminder.save()

    except Exception:

        print traceback.format_exc()

    return
Exemple #5
0
    def run_plugins (self):

        '''
            Run Plugins

            This is the main function responsible for executing
            the plugins that have been identified for this
            message.

            --
            @return None
        '''

        if not self.plugins:
            logger.warning('No plugins matched for this message.')
            return

        # Check with the ACL system what the status is of
        # the user that has sent the message
        can_send = self.check_acl()

        # Load the plugins from the configuration that
        # should not have ACL rules applied to them
        config.read(
            os.path.join(os.path.dirname(__file__), '../settings.ini'))
        acl_free_plugins = [x.strip() \
                            for x in config.get('advanced', 'no_acl_plugins', '').split(',')]

        for plugin in self.plugins:

            # Check that we are allowed to run this plugin. It
            # should either be bypassed from the ACL system
            # using settings.ini, or the user is allowed
            # to run plugins
            if not plugin['name'] in acl_free_plugins and not can_send:
                continue

            # Getting here, we should run this plugin.
            # Do it!
            try:

                logger.info('Running plugin: {plugin} for message {message_id}'.format(
                    plugin = plugin['name'],
                    message_id = self.response['message_id']))

                logger.debug('Loading plugin: {plugin}'.format(
                    plugin = plugin['name']))

                # Find and Load the plugin from the file
                plugin_on_disk = PluginLoader.find_plugin(plugin['name'])
                loaded_plugin = PluginLoader.load_plugin(plugin_on_disk)

                # If we got None from the load, error out
                if not loaded_plugin:
                    logger.critical('Loading plugin {name} returned nothing.'.format(
                        name = plugin['name']))

                    continue

                # Run the plugins run() method
                plugin_output = loaded_plugin.run(self.response)

            except Exception, e:

                logger.error('Plugin {plugin} failed with: {error}: {trace}'.format(
                    plugin = plugin['name'],
                    error = str(e),
                    trace = traceback.print_exc()))

                continue

            # If we should be replying to the message,
            # do it.
            if loaded_plugin.should_reply():

                # Check what the reply type should be. Plugins
                # that don't specify one will default to text
                reply_type = 'text'
                if hasattr(loaded_plugin, 'reply_type'):
                    reply_type = loaded_plugin.reply_type()

                Telegram.send_message(self.sender_information, reply_type, plugin_output)

            # GC the loaded_plugin
            loaded_plugin = None
    def run_plugins(self):
        '''
            Run Plugins

            This is the main function responsible for executing
            the plugins that have been identified for this
            message.

            --
            @return None
        '''

        if not self.plugins:
            logger.warning('No plugins matched for this message.')
            return

        # Check with the ACL system what the status is of
        # the user that has sent the message
        can_send = self.check_acl()

        # Load the plugins from the configuration that
        # should not have ACL rules applied to them
        config.read(os.path.join(os.path.dirname(__file__), '../settings.ini'))
        acl_free_plugins = [x.strip() \
                            for x in config.get('advanced', 'no_acl_plugins', '').split(',')]

        for plugin in self.plugins:

            # Check that we are allowed to run this plugin. It
            # should either be bypassed from the ACL system
            # using settings.ini, or the user is allowed
            # to run plugins
            if not plugin['name'] in acl_free_plugins and not can_send:
                continue

            # Getting here, we should run this plugin.
            # Do it!
            try:

                logger.info(
                    'Running plugin: {plugin} for message {message_id}'.format(
                        plugin=plugin['name'],
                        message_id=self.response['message_id']))

                logger.debug(
                    'Loading plugin: {plugin}'.format(plugin=plugin['name']))

                # Find and Load the plugin from the file
                plugin_on_disk = PluginLoader.find_plugin(plugin['name'])
                loaded_plugin = PluginLoader.load_plugin(plugin_on_disk)

                # If we got None from the load, error out
                if not loaded_plugin:
                    logger.critical(
                        'Loading plugin {name} returned nothing.'.format(
                            name=plugin['name']))

                    continue

                # Run the plugins run() method
                plugin_output = loaded_plugin.run(self.response)

            except Exception, e:

                logger.error(
                    'Plugin {plugin} failed with: {error}: {trace}'.format(
                        plugin=plugin['name'],
                        error=str(e),
                        trace=traceback.print_exc()))

                continue

            # If we should be replying to the message,
            # do it.
            if loaded_plugin.should_reply():

                # Check what the reply type should be. Plugins
                # that don't specify one will default to text
                reply_type = 'text'
                if hasattr(loaded_plugin, 'reply_type'):
                    reply_type = loaded_plugin.reply_type()

                Telegram.send_message(self.sender_information, reply_type,
                                      plugin_output)

            # GC the loaded_plugin
            loaded_plugin = None