[Zope-dev] How to trigger Zope externally (mail)

Jean Jordaan jean@upfrontsystems.co.za
Thu, 27 Feb 2003 11:01:51 +0200


This is a multi-part message in MIME format.
--------------060807030809050703010107
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Andy McKay wrote:
> Or just write a simple HTTP post using Python. Have a look around for 
> the MailIn Product, or CMFMailIn which does this very simply and works 
> fine for low volume traffic (eg: fine listening to zope@zope.org).

Here's a very simple example that we're using to glue cron to
Zope. It does a GET, but you could just as easily make it do a POST.
I can't remember where I cribbed from ;]

-- 
Jean Jordaan
http://www.upfrontsystems.co.za

--------------060807030809050703010107
Content-Type: text/plain;
 name="trigger.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="trigger.py"

#!/usr/bin/python

username="user"
password="secret" # this is only example, of course
zope="http://localhost:17081"

import sys, urllib

class NoGUI_URLopener(urllib.FancyURLopener):

   def __init__(self, username, password, *args):
      apply(urllib.FancyURLopener.__init__, (self,) + args)

      self.username = username
      self.password = password
      self.asked = 0


   def prompt_user_passwd(self, host, realm):
      if self.asked:
         raise "Unauthorised"
      else:
         self.asked = 1
         return self.username, self.password



urllib._urlopener = NoGUI_URLopener(username, password)
urllib.urlretrieve("%s/cron_hook" % zope )

--------------060807030809050703010107--