[Zope3-Users] Periodically refresh RSS feeds

Thierry Florac thierry.florac at onf.fr
Tue Dec 19 03:44:41 EST 2006


Le mardi 19 décembre 2006 à 08:17 +0100, Christian Theune a écrit :
> Hi,
> 
> Florian Lindner wrote:
> > Hello,
> > I have the following situation:
> > 
> > An object represents an RSS feed. It should be updated like every 20 minutes. 
> > If there is something new a Jabber message should be send out.
> > 
> > Currently I have it implemented with an scheduler loop that emits an 
> > refreshRSSFeed event evey 20 minutes. My problem is that a handler for an 
> > event must be a static function, but I want a handler function to be called 
> > as a member of every instantiated RSS feed object.
> > 
> > Another idea I have:
> > Implement an utility where the RSS feeds could register a function that is 
> > called every 20 minutes.
> > Another way would be that this utility takes an URL and monitors the URL for 
> > changes and only notifies the RSS Feed object in case of a change.
> >
> > How would you do that?
> 
> So there's two problems here: scheduling and notifying persistent
> objects about an event.
> 
> I don't have a good idea about the scheduling right now, except the hint
> that using a 'zopectl run' script might be worthwhile.  I'm not sure
> what a 'scheduler function is'.
> 
> About notifying persistent objects: There is a method
> 'getAllUtilitiesRegisteredFor(interface)' which might help you. Have a
> look at zope/app/catalog/catalog.py beginning from line 150
> (indexDocSubscriber) how the catalog handles events and dispatches them
> to multiple catalogs. I think this pretty much matches your use case if
> you make each RSS feed a (named) utility.
> 
> Of course you could also have a utility that maintains references to all
> RSS feed objects and simply loops over them and calls a method for
> refreshing.


Hi,

I had a several problem to handle regular "alerts" which I solved in
this way :
 - scheduling in done via the "schedule" package, available from Zope3
SVN ; I created an "AlertManager" utility which is a subclass of
scheduler.CronTask (because my alerts are launched at fixed time, but
you can use other classes)
 - objects which can raise alerts are registered with a specific
interface IAlert
 - when the AlertManager is launched, it opens a new connection (via
ZEO.ClientStorage), search for registered components (via
zapi.getAllUtilitiesRegisteredFor(IAlert)) and call one of the
interface's methods which may raise the alert. In my use case an email
is sent, but it could be any kind of alert that Python can handle.

I'm far to know if this is the best approach, but at least it works
quite efficiently...

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.florac at onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85



More information about the Zope3-users mailing list