Author Archive

Create a Google Wave “EmailBot” with Python

March 1st, 2010

In this tutorial we will create a simple Google Wave robot which sends email notifications when a blip has been submitted.

Before we start.

This tutorial is an extension onto my tutorial “Create your First Google Wave Robot with Python in 15 Minutes“. Although this is not necessary to read to complete this tutorial, It will be helpful.

Robot Description

Our Robot will, when added, send an email off to the owner saying it was successfully added into the wave. It will then wait for any blips and send an email with the contents of the blip and the author of the blip.

This means we need 2 event handlers. Both “WAVELET_SELF_ADDED” and “BLIP_SUBMITTED”.

Let’s get into it

We will just create a simple Google Wave Robot to work off.

from waveapi import events
from waveapi import model
from waveapi import robot
 
if __name__ == '__main__':
    myRobot = robot.Robot('myEmailRobot',
        image_url='http://corythompson.net/wp-content/uploads/CoryThompson.jpg',
        version='1',
        profile_url='http://corythompson.net/')
 
    myRobot.Run()

Because we are using the mail feature we need to add an extra import. And We will add some variables. Your from address has to be the email address you signed up to App Engine with. So most the time it will end with @gmail.com.

from google.appengine.api import mail  
 
TO_ADDRESS = "cory@corythompson.net"
FROM_ADDRESS = "coryjthompson@gmail.com"

Next we will create an event handler for “WAVELET_SELF_ADDED” and “BLIP_SUBMITTED”. This goes just above myRobot.Run()

    myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted) #Triggered when BLIP is submitted.
    myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) # Triggered when Robot Is Added

Now all that is left is the main logic. We will first create the OnRobotAdded function. This goes just bellow our variables “TO_ADDRESS” and “FROM_ADDRESS” variables.

def OnRobotAdded(properties, context):
    """Invoked when the robot has been added."""
    root_wavelet = context.GetRootWavelet()
    root_wavelet.CreateBlip().GetDocument().SetText("Sending email updates to " + TO_ADDRESS) # Notifies Wave Users
    mail.send_mail(TO_ADDRESS, FROM_ADDRESS, "EmailBot Added", "You have been added to a google wave conversation") #Sends email to bot owner.

Last but definitely not least is adding the “OnBlipSubmitted” event.

def OnBlipSubmitted(properties,context):
    blip = context.GetBlipById(properties['blipId'])
    contents = blip.GetDocument().GetText() #Get's contents of blip
    mail.send_mail(TO_ADDRESS, FROM_ADDRESS, "EmailBot Notification", blip.GetCreator() + " says " + contents) # Sends email

And the whole code all at once

from waveapi import events
from waveapi import model
from waveapi import robot
from google.appengine.api import mail  
 
TO_ADDRESS = "cory@corythompson.net"
FROM_ADDRESS = "coryjthompson@gmail.com"
 
def OnRobotAdded(properties, context):
    """Invoked when the robot has been added."""
    root_wavelet = context.GetRootWavelet()
    root_wavelet.CreateBlip().GetDocument().SetText("Sending email updates to " + TO_ADDRESS) # Notifies Wave Users
    mail.send_mail(TO_ADDRESS, FROM_ADDRESS, "EmailBot Added", "You have been added to a google wave conversation") #Sends email to bot owner. 
 
def OnBlipSubmitted(properties,context):
    blip = context.GetBlipById(properties['blipId'])
    contents = blip.GetDocument().GetText() #Get's contents of blip
    mail.send_mail(TO_ADDRESS, FROM_ADDRESS, "EmailBot Notification", blip.GetCreator() + " says " + contents) # Sends email
 
if __name__ == '__main__':
    myRobot = robot.Robot('myEmailRobot',
        image_url='http://corythompson.net/wp-content/uploads/CoryThompson.jpg',
        version='1',
        profile_url='http://corythompson.net/')
 
    myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted)
    myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded)
    myRobot.Run()

That wraps up this tutorial, upload and test it out! If your having and problems just comment and ill help you with anything as quick as possible.

TwitterMalism

February 18th, 2010

This is a simple Python based Twitter client. It was created with minimalism in mind and was created for my eeepc which had trouble running clients such as TweetDeck. It was created using the python-twitter wrapper by DeWitt Clinton. This code is released under GPL and I encourage people to improve my code.

Screenshot

Usage

python twittermalism.py username password

Code

import twitter, time, pynotify, sys, urllib2
 
BUFFER_SIZE = 1024
 
#Signs into twitter.
try:
    api=twitter.Api(username=sys.argv[1], password=sys.argv[2])
except:
    print "Username or password not entered"
    print "Usage: twittermal.py username password"
    sys.exit(1)
 
#initialize the notifications module.
pynotify.init("Basics")
 
 
def load_icon(url):
    """Try to download and load the icon."""
    try:
        from gtk.gdk import PixbufLoader
 
        stream = urllib2.urlopen(url)
 
        loader = PixbufLoader()
        data = stream.read(BUFFER_SIZE)
        while data:
            loader.write(data)
            data = stream.read(BUFFER_SIZE)
        stream.close()
        loader.close()
 
        icon = loader.get_pixbuf()
 
        return icon
    except (ValueError, KeyError, ImportError, urllib2.URLError):
        pass
 
#Infinate loop with main logic.
while True:
    f_timeline=api.GetFriendsTimeline()
    now = time.mktime(time.gmtime())
    for u in f_timeline:
 
        statustime = time.mktime(time.strptime(u.created_at + ' UTC',  '%a  %b %d %H:%M:%S +0000 %Y %Z'))
 
        if ((statustime+61)>now):
            #Send update.
            n = pynotify.Notification(u.user.name, u.text)
            icon = load_icon(u.user.profile_image_url)
            n.set_icon_from_pixbuf(icon)
            n.show()
    time.sleep(60)

Future Development

I would like to create a GUI that sits in the system tray. When the user clicks this icon the user will be able to tweet or close the application.

Download

TwitterMalism.tar.gz
TwitterMalism.zip

Create your First Google Wave Robot with Python in 15 Minutes

December 12th, 2009

In this post you’ll discover how to create your first Google Wave Robot. This tutorial is aimed at complete beginners and should take no more then 15 minutes. By the end of the tutorial you will have a simple Google Wave Robot.
Read more »

Build a home media server for PS3, Xbox 360 or PC (Ubuntu)

November 13th, 2009

mediacentreComputer manufacturers are coming out with expensive home media servers which work just as well as an old, dusty computer with some FREE software. In this article we will cover how to build your own home media server with the capabilities of streaming to most devices on your network such as PS3, Xbox 360 and other computers.
Read more »

FmylifeBOT – A Google Wave Robot Example

October 25th, 2009

FmylifeBOT is a robot for Google Wave. When added to a wave it will introduce itself and then waits for a blip (message) starting with FML. Once found it will replace the text FML with a random entry on the popular website fmylife.com. This robot was created for educational purposes and for my entertainment more then anything.
Read more »

Recover Deleted Data from USB Flash Drive with Foremost

October 25th, 2009

flash drive

Have you ever deleted any important data from your computer on accident? Data that has been deleted remains on the drive until it’s overwritten. This is due to the fact that when a file is deleted it’s reference is deleted from the Master File Table (MFT) which references all of the files on a particular drive. When the reference is deleted from the MFT the operating system knows there is now free space that can be used, but the actual data remains on the disk unless overwritten. We can use data recovery tools such as Foremost to read all the data on the drive and recover as much as possible.
Read more »

How to Create a Simple Google Wave Robot in Python

October 16th, 2009

This tutorial has been moved!
Click here for new tutorial