#!/usr/bin/env python # GPL powered from iAggregatorLib.Mail import Mail,MailError from iAggregatorLib.Config import Config from iAggregatorLib.FeedCollector import FeedCollector, NotFound, \ TooYoung, FetchError, ParseError import sys # TODO: # - command line options support like: # --rc=otherRcFile # --usage # --help , -h # --version , -v class Aggregator: """ iAggregator uses Config, Mailer & FeedCollector to work peacefully by collecting some feeds on locations mentionned on the config file and mail them to some body. """ def __init__(self): # initialization code conf = Config() smtp, sender, recipients = conf.getMailInfos() self.mailer = Mail(smtp, sender, recipients) self.channels = conf.getChannels() self.finder = FeedCollector(conf.getCacheDir(), conf.getProcMail(), conf.getRuleTemplate()) def main(self): for channel in self.channels: # channel is the name associated with the location url url,refreshRate = self.channels[channel] try: feed = self.finder.collect(channel,url, refreshRate) except NotFound: print 'Did not found any feed on [%s]' % channel except TooYoung, e: print "Time scale '%s' not Ok for now. Retry in %s for [%s]" % (refreshRate,e.when,channel) except (ParseError,FetchError), e: print e else: # hey we've found something to mail for item in feed['items']: subject, txt, html = self.finder.formatFeed(feed,item) try: self.mailer.sendMail(channel,subject,txt,html) except MailError,msg: print "Unable to send email:%s" % msg print "Please fix your config" sys.exit(1) print '%d new items in [%s] feed' % (len(feed['items']),channel) if __name__ == '__main__': Aggregator().main()