Hands-On #5 Quick Email… with python and GTK Tuesday, Apr 29 2008 

A really simple way to send e-mail:

import pygtk
pygtk.require(‘2.0′)
import gtk
import smtplib

class DlgSendMail:
def onSend(self, widget, data=None):
fr = “your name”
to = self.txtTo.get_text()
ms = self.txtMsg.get_text()
smtp = smtplib.SMTP(’smtp.server.com.br’)
smtp.login(‘account@smtpservercom.br’, ‘password’)
smtp.sendmail(fr, to, ms)
smtp.quit()
gtk.mainquit()

def delete_event(self, widget, event, data=None):
print “delete event occurred”
return gtk.FALSE

def destroy(self, widget, data=None):
gtk.mainquit()

def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect(“delete_event”, self.delete_event)
self.window.connect(“destroy”, self.destroy)
self.window.set_border_width(10)
self.window.set_usize(300, 100)
self.window.set_title(“GTK SendMail”)

#create a 2×2 table
self.table = gtk.Table(3, 2, gtk.TRUE)
self.window.add(self.table)

#to label field
self.lblTo = gtk.Label(“To:”)
self.lblTo.set_alignment(1,1)
self.window.add(self.lblTo)
self.table.attach(self.lblTo, 0, 1, 0, 1)
self.lblTo.show()

#to Input field
self.txtTo = gtk.Entry()
self.window.add(self.txtTo)
self.table.attach(self.txtTo, 1, 2, 0, 1)
self.txtTo.show()

#message label field
self.lblMsg = gtk.Label(“Message:”)
self.lblMsg.set_alignment(1,1)
self.window.add(self.lblMsg)
self.table.attach(self.lblMsg, 0, 1, 1, 2)
self.lblMsg.show()

#message Input field
self.txtMsg = gtk.Entry()
self.window.add(self.txtMsg)
self.table.attach(self.txtMsg, 1, 2, 1, 2)
self.txtMsg.show()

#button send
self.button = gtk.Button(“Sent Now”)
self.button.connect(“clicked”, self.onSend, None)
self.button.connect_object(“clicked”, self.window.destroy, self.window)
self.window.add(self.button)
self.table.attach(self.button, 0, 2, 2, 3)
self.button.show()

#show everything
self.table.show()
self.window.show()

def main(self):
gtk.main()

if __name__ == “__main__”:
dlg = DlgSendMail()
dlg.main()

Hands-On #4 Retrieving a list of the user calendars Monday, Apr 28 2008 

Print a list of the defined user calendars:

try:
from xml.etree import ElementTree # for Python 2.5 users
except ImportError:
from elementtree import ElementTree
import gdata.calendar.service
import gdata.service
import atom.service
import gdata.calendar
import atom
import getopt
import sys
import string
import time

def PrintUserCalendars(calendar_service):
  feed = calendar_service.GetAllCalendarsFeed()
  print feed.title.text
  for i, a_calendar in enumerate(feed.entry):
    print '\t%s. %s' % (i, a_calendar.title.text,)

def main():
  calendar_service = gdata.calendar.service.CalendarService()
  calendar_service.email = ';-@gmail.com'
  calendar_service.password = ':o('
  calendar_service.source = 'Google-Calendar_Python_Sample-1.0'
  calendar_service.ProgrammaticLogin()
  PrintUserCalendars(calendar_service)

if __name__ == '__main__':
 main()

Hands-On #03 Generating a Google Doc file list Friday, Apr 25 2008 

  • Download the file tc02.zip
  • Uncompress it
  • Edit the listdocs.py file and replace the e-mail/password
  • Run the dev_appserver.py

The dev_appserver should be already fixed – see the previous post.

Hands-On #02 Fixing dev_appserver for xml parsing use Friday, Apr 25 2008 

It seems that the dev_appserver.py module is not prepared for C_EXTENSION as well. As consequence, the xml parser pyexpat can not be used. The google data python api, will use those feature when retrieving list of feeds as shown below:

client = gdata.docs.service.DocsService()
client.ClientLogin(‘your_email@gmail.com’, ‘your_password’)
documents_feed = client.GetDocumentListFeed()

The bold line will work fine on python enviroment, but it will crash when running under the dev_appserver control.

There is already an opened issue (http://code.google.com/p/googleappengine/issues/detail?id=83)

The suggested workaround solved my problem:

“Change lines 1140-1141 of dev_appserver.py from:

if (file_type != self._imp.C_BUILTIN and
not FakeFile.IsFileAccessible(pathname)):

to:

if (file_type != self._imp.C_BUILTIN and
file_type != self._imp.C_EXTENSION and
not FakeFile.IsFileAccessible(pathname))”

The dev_appserver.py file can be located at <Installation dir>\Google
\google_appengine\google\appengine\tools

Hands on – For a sustainable world… Thursday, Apr 17 2008 

Just disclosing some great ideas -
PT – Apenas divulgando algumas grandes idéia…

Pity, all texts are in portuguese!
Any volunteer?

Hands On #1 – Google App Engine Wednesday, Apr 16 2008 

Target Development Enviroment

  • MS Windows XP/2000
  • Requisites:
    • here the suggested folder was used:
      C:\Python25
  • Google App Engine SDK Installed
    • here the suggested folder was used:
      %ProgramFiles%googlegoogle_appengine

      e.g: C:Program Filesgooglegoogle_appengine

    • Install the sample application:
      • Application 1: tc01
      • Description: Test Case 01 – tc01 – Add two numbers and Guest book application
      • Installation:
    • Download the application tc01.zip file
    • Uncompress its content (TC01) in temporary folder (for instance: C:\Temp)
      e.g: C:\temp\tc01
  • open a command prompt
    • go to previous application folder (C:temp in my case)
    • type:
      C:> cd temp
    • run the application web server:
    • type:
      dev_appserver.py tc01
  • Execution:
    • browse the url:
      http://localhost:8080/