Send email when static page loads?

Posted on
Sat Mar 01, 2008 2:30 pm
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

Send email when static page loads?

Hi,
I am accessing a static htm file in IndigoWebServer/static and was wondering if there is any way to either log when the page is requested or even better to email me when it is requested. Or, possibly run an AppleScript when it is requested?

Thank you,

James

Posted on
Sun Mar 02, 2008 7:40 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Send email when static page loads?

Hi James,

Not easily for a static HTML page. You could, however, define a new dynamic page using a Python request handler (see IndigoWebServer/indigopy/indigoreqhandler.py for the main request handlers used by Indigo). Those functions are called when that page is requested. So, for example, if you added a function like this:
Code: Select all
   def foobar(self):
      self._Log("foobar page requested from " + cherrypy.request.remote_addr)
      return "hello there"
   foobar.exposed = True

Then every time you try to access "/foobar" on the web sever it will log to the Indigo Event Log file. You can also, via Python, have it return the contents of your static HTML file within that function.

Regards,
Matt

Posted on
Mon Mar 03, 2008 10:46 am
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Hi Matt,

Ok, thank you. Got that working! Can python run an Applescript?

Sorry to take time away from development to answer such trivial questions...

James

Posted on
Tue Mar 04, 2008 9:10 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

Hi James,
737SimGuy wrote:
Ok, thank you. Got that working! Can python run an Applescript?

Yes, look at Example #3 here.

737SimGuy wrote:
Sorry to take time away from development to answer such trivial questions...

No problem at all... glad to help you get this working.

Regards,
Matt

Posted on
Sat Mar 08, 2008 11:01 am
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Yes, look at Example #3 here.


I have been trying to get this to work, but to no avail. I try to call the function from within the "def index(self):" function in reqhandler.py which is in my plugin folder. I get the log entries, so I know I'm getting into the function, but it just won't work. I made sure to import os. Have you actually done this?

Thanks,

James

Posted on
Sat Mar 08, 2008 11:09 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

No, I haven't tried it yet. Copy/paste what you are trying so I can take a look at it. Also add log statements both before and after your AppleScript call so you can see if the AppleScript call is failing and throwing out of the function (if the 2nd log function isn't called, then it is).

Matt

Posted on
Sat Mar 08, 2008 12:17 pm
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Hi,

Here is the function:
Code: Select all
##########################
def index(self):
      # Push a log message to Indigo's Event Log window.
      
      self._Log("Just before applescript call")
      cmd = """osascript -e 'tell app "Finder" to sleep'"""
      os.system(cmd)
      self._Log("Just after applescript call")
            
      # Override the returned content type to be plain text instead of HTML.
      cherrypy.response.headers['Content-Type'] = 'text/plain'
      return u"Hi Debbie!"
   index.exposed = True      
###############################

Here is the log:

###############################
Mar 8, 2008 10:10:33 AM
  Trigger Action     start background tasks
  Connected to USB ActiveHome Interface
  CM15 firmware version 1
  Client connected
  WebServer          started on port 8176 -- digest authentication enabled
  WebServer          enabled browser access to plugin path "plugins/jims/static"
  Client connected

Mar 8, 2008 10:12:12 AM
  WebServer          Just before applescript call
  WebServer          Just after applescript call
###################################


James

Posted on
Sat Mar 08, 2008 12:56 pm
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

Trying using the absolute path for osascript:

Code: Select all
      cmd = """/usr/bin/osascript -e 'tell app "Finder" to sleep'"""


Matt

Posted on
Sat Mar 08, 2008 2:37 pm
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Hi Matt,

Thank you that works! It seems to run several of the applescript tests I have done except for the one I really want, naturally. Trying to send an email to alert me when this page has been accessed. I tried using my normal applescript for this but it doesnt work from the osascript command, maybe not supported? Would be better if I could simply call an external applescript, so I am experimenting with that. Here is what I use in normal applescript to send an email:

tx = "Hi"
send email to "myaddress (at symbol) my domain" with subject "Accessed web page" with body tx

Works fine normally, but not from the osascript. Frustrating.

Oh, and it seems I need to restart the computer for any modifications to the handler.py to work. Stopping and starting the Indigo sever doesn't do it.

Thanks for everything!

James

Posted on
Sat Mar 08, 2008 3:31 pm
737SimGuy offline
Posts: 23
Joined: Oct 29, 2007

(No subject)

Matt,

Further to my last:

I have re-discovered, if you will, that the "send email" command only works within Indigo triggers. DOH! I was thinking it was regular ol Applescript. Obviously you have the mail function in your library. So, I am researching sending an email with regular Applescript now. Ugh.

Any ideas?

James

Posted on
Sun Mar 09, 2008 9:30 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

(No subject)

Hi James,

You should be able to call the send email verb by putting inside a tell app "IndigoServer" and end tell block.

Regards,
Matt

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests