Search This Blog

Wednesday 14 May 2014

Keywords from emails on Google App Engine

Today I was working on a project which needed to have a summary of comments (especially emails) sent by the staff working on it.

The software runs on Google App Engine (because I wrote it), so it was surprisingly easy to add this courtesy of AlchemyAPI.

App Engine can receive emails, that's just a matter of adding to the app.yaml configuration.

inbound_services:
- mail

- url: /_ah/mail/.+
  script: emailmgmt.app
  login: admin

Skipping most of the actual program, it was essentially this.

class EmailHandler(InboundMailHandler):

  def receive(self,message):
   (content_type,body) = message.bodies().next()
   a = alchemyapi.AlchemyAPI()
   data = a.keywords('html',body.decode(),{'sentiment':1})
   for k in data['keywords']:
      # store keywords and sentiment analysis 
   
That extracts the body out of the email, calls out to the Alchemy API, and returns the keywords from the email including the sentiment of the words around it (whether the word is positive or negative).

A bit of JavaScript had it displaying the keywords in colour. I sent the following email:

From: gregb@ifost.org.auTo: fun@app.appenginemail.comSubject: Site report 
They had some lovely stone gargoyles and some horrible fountains.

And out came some coloured summary keywords: stone gargoyles, fountains.


Greg Baker (gregb@ifost.org.au) is an independent consultant. If you are an industry leader and you need someone to catch your vision and help you make it reality, Greg might well be the right person to call.

No comments:

Post a Comment