Example #1
0
    def onLoadConfig(self):
        self._adminPlugin = self.console.getPlugin('admin')
        self._msg = MessageLoop()

        try:
            self._rate = self.config.get('settings', 'rate')
            self.info('adv rate is %s' % self._rate)
        except:
            self.error('config missing [settings].rate')
            return False

        if self.config.has_option('settings', 'ads'):
            self._fileName = self.console.getAbsolutePath(self.config.get('settings', 'ads'))
            self.loadFromFile(self._fileName)
        else:
            self._fileName = None
            self.loadFromConfig()

        try:
            self._feed = self.config.get('newsfeed', 'url')
        except:
            pass

        try:
            self._feedmaxitems = self.config.getint('newsfeed', 'items')
        except:
            pass
        #reduce feedmaxitems 1 point, since we're starting at item 0, this makes counting easier...
        self._feedmaxitems -= 1
        self.verbose('self._feedmaxitems: %s' % self._feedmaxitems)

        try:
            self._feedpre = self.config.get('newsfeed', 'pretext')
        except:
            pass

        #test if we have a proper feed
        if self._feed is not None:
            if self._feed.strip() == '':
                self._feed = None
            else:
                f = feedparser.parse(self._feed)

                if not f or f['bozo'] == 1:
                    self._feed = None
                    self.warning('Error reading feed at %s' % self._feed)
                    self.debug(f['bozo_exception'])

        if self._cronTab:
            # remove existing crontab
            self.console.cron - self._cronTab

        (min, sec) = self._getRateMinSec()
        self._cronTab = b3.cron.PluginCronTab(self, self.adv, second=sec, minute=min)
        self.console.cron + self._cronTab
Example #2
0
    def onLoadConfig(self):
        self._adminPlugin = self.console.getPlugin('admin')

        self._msg = MessageLoop()

        try:
            self._rate = self.config.getint('settings', 'rate')
        except:
            self.error('config missing [settings].rate')
            return False

        if self.config.has_option('settings', 'ads'):
            self._fileName = self.console.getAbsolutePath(self.config.get('settings', 'ads'))
            self.loadFromFile(self._fileName)
        else:
            self._fileName = None
            self.loadFromConfig()

        try:
            self._feed = self.config.get('newsfeed', 'url')
        except:
            pass

        try:
            self._feedmaxitems = self.config.getint('newsfeed', 'items')
        except:
            pass
        #reduce feedmaxitems 1 point, since we're starting at item 0, this makes counting easier...
        self._feedmaxitems -= 1
        self.verbose('self._feedmaxitems: %s' %self._feedmaxitems)

        try:
            self._feedpre = self.config.get('newsfeed', 'pretext')
        except:
            pass

        #test if we have a proper feed
        f = feedparser.parse(self._feed)
        _feedtitle = f['feed']['title']
        if _feedtitle:
            self.debug('Opening feed: %s' %_feedtitle)
        else:
            # empty the feed all together
            self._feed = None
            self.debug('Feed is not a proper feed, or unreachable. Disabling the feedparser')

        if self._cronTab:
            # remove existing crontab
            self.console.cron - self._cronTab

        self._cronTab = b3.cron.PluginCronTab(self, self.adv, 0, '*/%s' % self._rate)
        self.console.cron + self._cronTab
Example #3
0
 def getFeed(self, ad):
     i = ad.split()
     if len(i) == 2 and type(i) == type(1):
         i = i[1]
         self._feeditemnr = i
     else:
         if self._feeditemnr > self._feedmaxitems:
             self._feeditemnr = 0
         i = self._feeditemnr
     try:
         f = feedparser.parse(self._feed)
     except:
         self.debug('Not able to retrieve feed')
         return None
     try:
         _item = f['entries'][i]['title']
         self._feeditemnr += 1
         return self._feedpre + _item
     except:
         self.debug('Feeditem %s out of range' % i)
         self._feeditemnr = 0
         return None