March 2010
Intermediate to advanced
304 pages
8h 23m
English
You can browse or check out the source code at http://code.google.com/p/geo-bot.
from waveapi import events from waveapi import robot from waveapi import element from waveapi import ops from waveapi import appengine_robot_runner import urllib from google.appengine.api import urlfetch from xml.dom import minidom def OnRobotAdded(event, wavelet): """Invoked when the robot has been added.""" badge = 'http://geo-bot.appspot.com/images/geo-bot-badge.png' image = element.Image(url=badge, width=220, height=35) root_blip = wavelet.root_blip new_blip = root_blip.reply() new_blip.append(image) GeoProcess(root_blip) def OnBlipSubmitted(event, wavelet): """Invoked when a blip is sent to the wavelet. Gets new blip and passes blip to GeoProcess function""" blip = event.blip GeoProcess(blip) def GeoProcess(blip): """Send blip information to Yahoo! Placemaker via YQL query""" contents = blip.text.replace('"', ' ') utf_contents = contents.encode('utf-8') #Set up the form fields for the request to the YQL service form_fields = { 'q': 'SELECT * FROM geo.placemaker WHERE \ documentContent="' + utf_contents + '" AND documentType="text/plain"', 'format': 'xml' } #Encode the form data form_data = urllib.urlencode(form_fields) #Send the request to YQL API, with encoded form field data #If the request is successful, parse and update content in blip url = 'http://query.yahooapis.com/v1/public/yql' content_type = 'application/x-www-form-urlencoded' result = urlfetch.fetch(url = url, payload = form_data, ...