Archive for April, 2008

 

A little bit of python:

This week i played a bit around with pyton. Had never used it before so wanted to get a feel of it and know what are its capabilities and what can be done with it. I used it for the mobile web server so could not use any UI aspects of it.First i had to dload the mobile web server and install it into the phone.

For the web browser we need two files to be made.

The first one has the following code:

# 1. Register Python file extension
AddHandler mod_python .py
# 2. Add our own handler
# Basically this means that test.py will be executed when files with .py
# extension are requested from this directory
PythonHandler test
# 3. Toggle debug on to make life easier in error situation
PythonDebug On
# 4. Turn all options off
Options None
# 5. Deny access to Python compiled files
Order Deny,Allow
Allow from all
<FilesMatch “\.(pyc)$”>
Deny from all
</FilesMatch>

save it as ht.acl

The second is where all the code goes in. I made a small application which runs in the server. So when you go to www.sanjaypapinazath.mymobilesite.net/test/.py it sends out an sms automatically to mine and Josh’s phone from my mobile.

# S60 System Stuff
import e32
import messaging

# 1. Define request handler
def handler(req):

# 2. Import necessary Apache modules
from mod_python import apache

nbr1 = “774-254-1237″ # change the mobile number here
nbr2 = “212-748-9286″# change the mobile number here
txt = u”Greetings from the dead biatch:”
messaging.sms_send(nbr1, txt)
messaging.sms_send(nbr2, txt)

# 3. Set correct content type to request
req.content_type = ‘text/html’

# 4. Generate simple HTML page
req.write(”<html>Hello World”)
req.write(”</html>”)

# 5. Return apache.OK to indicate that page handling was successful
return apache.OK

Save this as test.py in notepad and upload it in a folder called test located in the data/webserver directory in the mobile.

Posted by admin under Uncategorized  •  No Comments