you either surf or you fight

Post on 08-May-2015

3.450 Views

Category:

Technology

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

Integrating Library Services with Google Wave

TRANSCRIPT

You Either Surf or You Fight: Integrating Library Services With

Google Wave

Sean HannanSheridan Libraries

Johns Hopkins University

Google Wave

• http://wave.google.com• Collaborative platform

Why Library Services there?

• You can’t always force users to come to you• Go where they are

Wave Apps

• Two types – Gadgets• Like existing iGoogle gadgets

– Robots• Real-time interaction

• Let’s go for the real-time interaction

Already on Wave?

• Invite uncle-milty@appspot.com to a conversation

Creating a Wave Robot

• Libraries for Java and Python• Deployment using Google AppEngine

App Engine

• http://appengine.google.com• Google’s cloud-computing platform• Free for up to 1.3 million requests per day

Set up the Application

• Create an application at appengine.google.com

• Set up an application identifier <app>.appspot.com

App Engine SDK

• Download the App Engine SDK from http://code.google.com/appengine/downloads.html

• Start the App Engine Launcher and create a new application

Set up the app.yaml

application: uncle-miltyversion: 2runtime: pythonapi_version: 1

handlers:- url: /_wave/.* script: uncle-milty.py- url: /assets static_dir: assets

Wave Robot API

• Download the files from svn:– svn checkout http://wave-robot-python-

client.googlecode.com/svn/trunk/src/waveapi waveapi

• Drop it in the application directory

Wave Concepts

• Wavelet– The conversation taking place within Google Wave

• Blip– Every message as part of the wavelet– Hierarchical

• Each of these have unique identifiers that can be used to programmatically address them

Project Overview

• A simple chat bot• Searches the library catalog for results

Code it up!

• Available on github: http://github.com/MrDys/uncle-milty

External Libraries

• External libraries are a-okay• Just drop it in the project directory• Going to use BeautifulSoup to scrape the

OPAC

Imports

from waveapi import eventsfrom waveapi import modelfrom waveapi import robotfrom waveapi import documentfrom waveapi.ops import OpBuilder

import loggingimport urllib2from BeautifulSoup import BeautifulSoup

OnRobotAdded Function

def OnRobotAdded(properties, context): """Invoked when the robot has been added.""" logging.debug("created") root_wavelet = context.GetRootWavelet()

root_wavelet.CreateBlip().GetDocument().SetText("Hi, I'm Milton S. Eisenhower and I'd be happy to help you with your research. I will search the JHU catalog for anything that you say to me and I'll let you know if I find anything.")

OnBlip Submitted Function

def OnBlipSubmitted(properties, context): blip = context.GetBlipById(properties['blipId'])

page = urllib2.urlopen("https://catalog.library.jhu.edu/ipac20/ipac.jsp?menu=search&aspect=subtab22&npp=5&ipp=20&spp=20&profile=general&ri=&index=ALTITLE&term=" + blip.GetDocument().GetText() + "&x=0&y=0&aspect=subtab22")

OnBlipSubmitted Function con’t

soup = BeautifulSoup(page) results = soup.findAll(title="View more

information")

sub_blip = context.GetRootWavelet().CreateBlip()

sub_blipdoc = sub_blip.GetDocument()

OnBlipSumitted Function con’t

outputstr = "" count = 0

for i in results: if count >= 5: break else: itemstr = str(i) itemstr = itemstr.replace('class="smallBoldAnchor"', '') outputstr = outputstr + itemstr + "<br/>" count = count + 1

OnBlipSubmitted Function con’t

logging.debug(outputstr) sub_blipdoc.SetText(" ") builder = OpBuilder(context) builder.DocumentAppendMarkup(sub_blip.waveId,

sub_blip.waveletId, sub_blip.blipId, outputstr) logging.debug(sub_blip.waveId + " " +

sub_blip.waveletId + " " + sub_blip.blipId)

Register Event Handlers

if __name__ == '__main__': myRobot = robot.Robot('Milton S. Eisenhower', image_url='http://uncle-milty.appspot.com/assets/milty.png', version='2', profile_url='http://uncle-milty.appspot.com/') myRobot.RegisterHandler(events.BLIP_SUBMITTED,

OnBlipSubmitted) myRobot.RegisterHandler(events.WAVELET_SELF_ADDED,

OnRobotAdded) myRobot.Run()

Gotchas

• CSS– Doesn’t really like it, so keep it simple

• HTML Links– Won’t let you do it directly, must use OpBuilder

Deployment

• Just hit ‘Deploy’ in the App Engine Launcher

Debugging

• Use the logging library• View the log results in realtime on

http://appengine.google.com

What next?

• Could be improved in a lot of ways– More services integrated– Create a menu-like system to select options

Q&A

Questions?

top related