you either surf or you fight

27
You Either Surf or You Fight: Integrating Library Services With Google Wave Sean Hannan Sheridan Libraries Johns Hopkins University

Upload: mrdys

Post on 08-May-2015

3.450 views

Category:

Technology


5 download

DESCRIPTION

Integrating Library Services with Google Wave

TRANSCRIPT

Page 1: You Either Surf Or You Fight

You Either Surf or You Fight: Integrating Library Services With

Google Wave

Sean HannanSheridan Libraries

Johns Hopkins University

Page 2: You Either Surf Or You Fight

Google Wave

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

Page 3: You Either Surf Or You Fight

Why Library Services there?

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

Page 4: You Either Surf Or You Fight

Wave Apps

• Two types – Gadgets• Like existing iGoogle gadgets

– Robots• Real-time interaction

• Let’s go for the real-time interaction

Page 5: You Either Surf Or You Fight

Already on Wave?

• Invite [email protected] to a conversation

Page 6: You Either Surf Or You Fight

Creating a Wave Robot

• Libraries for Java and Python• Deployment using Google AppEngine

Page 7: You Either Surf Or You Fight

App Engine

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

Page 8: You Either Surf Or You Fight

Set up the Application

• Create an application at appengine.google.com

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

Page 9: You Either Surf Or You Fight

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

Page 10: You Either Surf Or You Fight

Set up the app.yaml

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

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

Page 11: You Either Surf Or You Fight

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

Page 12: You Either Surf Or You Fight

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

Page 13: You Either Surf Or You Fight

Project Overview

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

Page 14: You Either Surf Or You Fight

Code it up!

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

Page 15: You Either Surf Or You Fight

External Libraries

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

OPAC

Page 16: You Either Surf Or You Fight

Imports

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

import loggingimport urllib2from BeautifulSoup import BeautifulSoup

Page 17: You Either Surf Or You Fight

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.")

Page 18: You Either Surf Or You Fight

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")

Page 19: You Either Surf Or You Fight

OnBlipSubmitted Function con’t

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

information")

sub_blip = context.GetRootWavelet().CreateBlip()

sub_blipdoc = sub_blip.GetDocument()

Page 20: You Either Surf Or You Fight

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

Page 21: You Either Surf Or You Fight

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)

Page 22: You Either Surf Or You Fight

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()

Page 23: You Either Surf Or You Fight

Gotchas

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

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

Page 24: You Either Surf Or You Fight

Deployment

• Just hit ‘Deploy’ in the App Engine Launcher

Page 25: You Either Surf Or You Fight

Debugging

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

http://appengine.google.com

Page 26: You Either Surf Or You Fight

What next?

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

Page 27: You Either Surf Or You Fight

Q&A

Questions?