def SetupRobot(): global myrobot myrobot = robot.Robot('Conference Bot') # Setup Oauth for domain of TOC wave myrobot.setup_oauth(wavecred.CONSUMER_KEY, wavecred.CONSUMER_SECRET, server_rpc_base=wavecred.RPC_BASE[wavecred.DOMAIN])
def __init__(self): self.robot = robot.Robot('Conference Bot') self.robot.setup_oauth( wavecred.CONSUMER_KEY, wavecred.CONSUMER_SECRET, server_rpc_base=wavecred.RPC_BASE[wavecred.DOMAIN]) webapp.RequestHandler.__init__(self)
def SetupRobot(): global myrobot myrobot = robot.Robot('Public Feedy') # Setup Oauth for domain of TOC wave myrobot.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=credentials.RPC_BASE[domain])
def create_robot(): service = robot.Robot(name=profiles.ROBOT_NAME, image_url=profiles.ROBOT_IMAGE_URL, profile_url=profiles.ROBOT_PROFILE_URL) service.register_profile_handler(profiles.ProfileResolver().get_profile) service.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=_RPC_BASE) return service
def makeWaveBlink(wavelet_ser, i): # Construct robot myrobot = robot.Robot('Blinky') # Construct wavelet wavelet = myrobot.blind_wavelet(wavelet_ser) # Setup Oauth myrobot.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=credentials.RPC_BASE[wavelet.domain]) if i % 2 == 0: wavelet.root_blip.all().annotate(blip.Annotation.COLOR, '#FFFFFF') else: wavelet.root_blip.all().annotate(blip.Annotation.COLOR, '#000000') myrobot.submit(wavelet)
def addLine(wavelet_ser, num): # Construct robot myrobot = robot.Robot('Scrolly') # Construct wavelet wavelet = myrobot.blind_wavelet(wavelet_ser) # Setup Oauth myrobot.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=credentials.RPC_BASE[wavelet.domain]) pattern = '>>>' line = '' for x in range(num): line += pattern line += '\n' wavelet.root_blip.append(line) myrobot.submit(wavelet)
#!/usr/bin/python2.4 from waveapi import robot from waveapi import events from waveapi import appengine_robot_runner def OnSelfAdded(event, wavelet): wavelet.reply('Ready to replace, matey!') def OnBlipSubmitted(event, wavelet): translations = {'yes': 'Yarr!', 'lol': 'Yo-ho-ho!'} for english, piratish in translations.items(): event.blip.all(english).replace(piratish) if __name__ == '__main__': robotty = robot.Robot('Pirate Speaky', image_url='', profile_url='') robotty.register_handler(events.WaveletSelfAdded, OnSelfAdded) robotty.register_handler(events.BlipSubmitted, OnBlipSubmitted) appengine_robot_runner.run(robotty, debug=True)
lines[-1] = lines[-1] + line else: lines.append(line) for line in lines: if line.startswith("%N "): token, id, description = tuple(line.split(" ", 2)) wavelet.reply( "Did you know that " + gadget.get('numbers') + " appears in the sequence: " + " ".join([s for s in description.split(" ") if s])) def OnSelfAdded(event, wavelet): blip = wavelet.root_blip blip.append( element.Gadget("http://jcgbot.appspot.com/static/gadget-final.xml")) if __name__ == '__main__': logging.info("Creating robot") myrobot = robot.Robot( "Greeter", image_url= 'http://google-wave-resources.googlecode.com/svn/trunk/samples/extensions/robots/python/conference-bot/img/avatar.png', profile_url='') myrobot.register_handler(events.WaveletSelfAdded, OnSelfAdded) myrobot.register_handler(events.GadgetStateChanged, OnGadgetChanged) appengine_robot_runner.run(myrobot, debug=True)
query = db.Query(models.SearchWave) waves = query.fetch(limit=40) self.PickOneWave(waves) self.PickOneWave(waves) self.PickOneWave(waves) def PickOneWave(self, waves): num = random.randint(0, len(waves) - 1) wave = waves[num] blind_wave = self.robot.blind_wavelet(wave.wave_json) ProcessWavelet(blind_wave) self.robot.submit(blind_wave) if __name__ == '__main__': wavey = robot.Robot( 'April ONeal', image_url='http://wave.google.com/wave/static/images/unknown.jpg') wavey.set_verification_token_info(credentials.VERIFICATION_TOKEN, credentials.ST) wavey.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=credentials.RPC_BASE[domain]) wavey.register_handler(events.WaveletSelfAdded, OnSelfAdded) wavey.register_handler(events.WaveletParticipantsChanged, OnParticipantsChanged) appengine_robot_runner.run(wavey, debug=True, extra_handlers=[('/web/cron', lambda: CronHandler(wavey))])
return blip = wavelet.root_blip blip.append(element.Line()) # Find all the line elements todo = [] for start, end in blip.all(element.Line): todo.append(start) # Sort by which line is first todo.sort() # Skip first 2 lines, since that's the title todo = todo[2:] # Reverse sort, so that we process bottom-up # and don't worry about our indices getting skewed todo.reverse() for position in todo: inline_blip = blip.insert_inline_blip(position) inline_blip.append('Rate this!') inline_blip.append(element.Gadget(url='http://www.nebweb.com.au/wave/likey.xml')) # Mark that we've procesed it wavelet.data_documents[PROCESSED] = 'done' if __name__ == '__main__': myRobot = robot.Robot('Inline Bliperator') myRobot.register_handler(events.WaveletSelfAdded, OnWaveletSelfAdded) myRobot.register_handler(events.BlipSubmitted, OnBlipSubmitted) appengine_robot_runner.run(myRobot)
id = wavelet.wave_id query = db.Query(models.WaveExport) query.filter('id =', id) waveExport = query.get() if waveExport is None: server = os.environ['SERVER_NAME'] url = "http://" + server + "/export?waveId=" + id.replace("+", "%252B") url_text = '%s&format=text' % url AddBlip(wavelet, "View export: \n%s\n%s\n" % (url, url_text)) waveExport = models.WaveExport() waveExport.id = id waveExport.title = wavelet.title waveExport.text = text waveExport.html = html waveExport.participants = [p for p in wavelet.participants] waveExport.put() if __name__ == '__main__': robotty = robot.Robot('Exporty', image_url='http://exporty-bot.appspot.com/avatar.png', profile_url='') robot_context = [events.Context.ALL] robotty.register_handler(events.BlipSubmitted, OnBlipSubmitted, context=robot_context) robotty.register_handler(events.WaveletSelfAdded, OnRobotAdded, context=robot_context) robotty.register_handler(events.WaveletParticipantsChanged, OnRobotAdded, context=robot_context) appengine_robot_runner.run(robotty, debug=True)
def __init__(self, robot): self._robot = robot webapp.RequestHandler.__init__(self) def get(self): address = '*****@*****.**' wavelet = self._robot.new_wave( domain=domain, participants=[address, '*****@*****.**'], submit=True) wavelet.title = ('Ways to use Wave') num = random.randint(0, len(content.messages) - 1) wavelet.root_blip.append(content.messages[num]) self._robot.submit(wavelet) if __name__ == '__main__': myrobot = robot.Robot( 'Pirate Treasure Hunt', image_url= 'http://www.traillink.com/images/mapIcons/national/stateMarker50.png') myrobot.set_verification_token_info(credentials.VERIFICATION_TOKEN, credentials.ST) myrobot.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, credentials.RPC_BASE[domain]) appengine_robot_runner.run(myrobot, debug=True, extra_handlers=[('/web/cron', lambda: CreateHandler(myrobot)) ])
file_data = urllib2.urlopen(url).read() attachment = element.Attachment(caption=address, data=file_data) return attachment def OnAnnotationChanged(event, wavelet): blip = event.blip text = blip.text # construct the todo outside of the loop to avoid # influencing what we're observing: todo = [] for ann in blip.annotations: if ann.name == ROBOT_KEY: logging.info('found it!') todo.append((ann.start, ann.end, ann.value)) for start, end, value in todo: payload = text[start:end] blip.range(start, end).clear_annotation(ROBOT_KEY) blip.at(end).insert(GetStaticMap(payload)) if __name__ == '__main__': robotty = robot.Robot( 'Static Mappy', image_url='http://staticmappy-bot.appspot.com/avatar.png') robotty.register_handler(events.AnnotatedTextChanged, OnAnnotationChanged, filter=ROBOT_KEY) robotty.register_handler(events.WaveletSelfAdded, OnAnnotationChanged) appengine_robot_runner.run(robotty, debug=True)
if len(value_split) > 1: url = 'http://%s%s' % (value_split[1], payload) else: continue blip.range(start, end).clear_annotation(ROBOT_KEY) if url: blip.range(start, end).annotate('link/manual', url) def OnSelfAdded(event, wavelet): """Invoked when any participants have been added/removed from the wavelet.""" Execute(event, wavelet) def OnDocumentChanged(event, wavelet): """Invoked when any participants have been added/removed from the wavelet.""" Execute(event, wavelet) def OnAnnotationChanged(event, wavelet): """Called when the document changes.""" # We only care about new docs which are indicated by datadocs: Execute(event, wavelet) if __name__ == '__main__': linker = robot.Robot('Wave Linker', image_url='http://www.seoish.com/wp-content/uploads/2009/04/wrench.png', profile_url='') linker.register_handler(events.WaveletSelfAdded, OnSelfAdded) linker.register_handler(events.AnnotatedTextChanged, OnAnnotationChanged, filter=ROBOT_KEY) appengine_robot_runner.run(linker, debug=True)
return # Find first line of blip to serve as title # Start after obligatory '\n' header_start = 1 # Default to ending after all the text header_end = len(blip.text) for start, end in blip.all(element.Line): # If we're past the first obligatory Line element, # assume we've seen some useful text and mark as end if start > 1: header_end = start break title = blip.text[header_start:header_end] # Add link to root blip to blip # Format is waveid://google.com/w+8hpKCBQNA/~/conv+root/b+Qq3cIxvuQ domain = wavelet.domain wave_id = wavelet.wave_id.split('!')[1] blip_ref = 'waveid://%s/%s/~/conv+root/%s/' % (domain, wave_id, blip_id) wavelet.root_blip.append(element.Line(line_type='li', indent=1)) wavelet.root_blip.append(title, [('link/manual', blip_ref)]) wavelet.root_blip.append('', [('link/manual', None)]) wavelet.data_documents[blip_id] = 'linked' if __name__ == '__main__': robotty = robot.Robot('BlipLinky', profile_url='') robotty.register_handler(events.BlipSubmitted, OnBlipSubmitted) appengine_robot_runner.run(robotty)
from google.appengine.ext import webapp from waveapi import appengine_robot_runner from google.appengine.ext import deferred import wavemaker import credentials class CreateHandler(webapp.RequestHandler): robot = None # override the constructor def __init__(self): webapp.RequestHandler.__init__(self) def get(self): num = int(self.request.get('num', '1')) for x in range(num): deferred.defer(wavemaker.MakeWave) self.response.out.write('Creating %s waves' % str(num)) if __name__ == '__main__': wavey = robot.Robot( 'Public Feedy', image_url='http://wave.google.com/wave/static/images/unknown.jpg') appengine_robot_runner.run(wavey, debug=True, extra_handlers=[('/web/create', lambda: CreateHandler())])
from google.appengine.ext import deferred import credentials import actions domain = 'wavesandbox.com' def OnSelfAdded(event, wavelet): wavelet.root_blip.append('Hello World') for i in range(21): deferred.defer(actions.makeWaveBlink, wavelet.serialize(), i, _countdown=i) if __name__ == '__main__': myrobot = robot.Robot( 'Blinky', image_url= 'http://media.giantbomb.com/uploads/0/3584/207911-1blinky_large.jpg') myrobot.register_handler(events.WaveletSelfAdded, OnSelfAdded) myrobot.set_verification_token_info(credentials.VERIFICATION_TOKEN, credentials.ST) myrobot.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base=credentials.RPC_BASE[domain]) appengine_robot_runner.run(myrobot, debug=True)
def ProcessAnnotations(event, wavelet): blip = event.blip todo = [] for ann in blip.annotations: if ann.name == ROBOT_KEY: todo.append((ann.start, ann.end, ann.value)) for start, end, value in todo: payload = blip.text[start:end] blip.range(start, end).clear_annotation(ROBOT_KEY) blip.range(start, end).delete() pos = min(start, len(blip.text) - 1) if value == 'blink': blip.at(pos).insert(element.Blink(payload)) elif value == 'marquee': blip.at(pos).insert(element.Marquee(payload)) if __name__ == '__main__': myRobot = robot.Robot( 'Best Robot Ever', image_url= 'http://best-website-ever.appspot.com/images/hamsterdance2.gif') myRobot.register_handler(events.WaveletSelfAdded, OnWaveletSelfAdded) myRobot.register_handler(events.BlipSubmitted, OnBlipSubmitted) myRobot.register_handler(events.AnnotatedTextChanged, OnAnnotationChanged, filter=ROBOT_KEY) appengine_robot_runner.run(myRobot)
parents = tokentype.split() # token types are hierarchical # the list is in this order with the most specific last for tok in parents[::-1]: if tok in COLORS: (color, bold) = COLORS[tok] self.annotateToken(tokenstring, color, bold) break self.end += len(tokenstring) return "" def OnLoad(event, wavelet): RecAnnotateBlips(event.blip) def RecAnnotateBlips(blip): """ Recursively traverse the wavelet tree""" HighlightBlip(blip) for child_blip in blip.child_blips: if child_blip: RecAnnotateBlips(child_blip) if __name__ == '__main__': lexers.get_all_lexers() myRobot = robot.Robot('syntaxy2', image_url='', profile_url='') myRobot.register_handler(events.DocumentChanged, OnBlipSubmit) myRobot.register_handler(events.WaveletSelfAdded, OnLoad) appengine_robot_runner.run(myRobot)
def logString(context, string): logging.info(string) addBlip(context, string) def addBlip(context, string): context.GetRootWavelet().CreateBlip().GetDocument().SetText(string) def OnRobotAdded(properties, context): rootWavelet = context.GetRootWavelet() waveTitle = rootWavelet.GetTitle() rootBlip = context.GetBlipById(rootWavelet.GetRootBlipId()) bodyWords = rootBlip.GetDocument().GetText().split(' ') response = urlfetch.fetch('http://www.abc.net.au/ra/rss/asiapacific.rss') if response.status_code == 200: dom = minidom.parseString(response.content) for node in dom.getElementsByTagName('title'): title = node.firstChild.data for word in bodyWords: logging.info("word: " + word + "|word") if title.find(word) > -1: addBlip(context, title) if __name__ == '__main__': myRobot = robot.Robot('FoxBot', version='3', image_url='http://pamela.fox.googlepages.com/foxbot.JPG', profile_url='') myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) myRobot.Run()
def CheckOverlap(annotations, match): for annotation in annotations: if annotation.start == match.start() and annotation.end >= match.end(): return True return False def AppendTweet(blip, start, tweetId): api = twitter.Api(cred.username, cred.password) status = api.GetStatus(tweetId) image = element.Image(status.user.profile_image_url) username = status.user.screen_name username_url = 'http://www.twitter.com/' + username text = status.text blip.append('...') #buffer blip.at(start).insert('\n') blip.at(start + 1).insert(image) blip.at(start + 3).insert(username + ': ' + text) blip.all(username + ': ').annotate('link/manual', username_url) if __name__ == '__main__': removey = robot.Robot( 'Tweet Expandey', image_url='http://www.seoish.com/wp-content/uploads/2009/04/wrench.png', profile_url='') removey.register_handler(events.BlipSubmitted, OnBlipSubmitted) appengine_robot_runner.run(removey, debug=True)
html = urllib2.urlopen(url).read() # I'm really sorry MLIA crew but you guys having an API would be totally cooler :) except: blip.GetDocument().SetText("I'm sorry, I had a fatal error, you can try again soon") quit() soupage = BeautifulSoup(html) a = soupage.findAll('div', 'sc') ab = a[r2].string.strip() blip.GetDocument().SetText(str(ab)) elif contents[:4].upper() == "AWOD": #TODO: find if in memcache cache. a = memcache.get("AWOD") if awod is None: url = "http://mylifeisaverage.com" html = urllib2.urlopen(url).read() soupage = BeautifulSoup(html) a = soupage.find('div',id='wotd').h1.string.strip() memcache.add("AWOD",a,43200) // 12 hours blip.GetDocument().SetText("The average word of the day is: %s" % str(a)) if __name__ == '__main__': myRobot = robot.Robot('mliawavebot', image_url='http://mliawavebot.appspot.com/static/icon.png', version='1', profile_url='http://harrisony.com/blog/2009/10/mlia-google-wave/') myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSumbitted) myRobot.Run(debug=True)
wavelet.title = ('Note') wavelet.root_blip.append(note) wavelet.root_blip.append('\n\nNoted from: %s' % url) self._robot.submit(wavelet) if wavelet.wave_id: json = '{"status": "success", "wave_id": "%s"}' % wavelet.wave_id else: json = '{"status": "error"}' if callback: self.response.out.write(callback + '(' + json + ')') else: self.response.out.write(json) if __name__ == '__main__': myrobot = robot.Robot( 'Wave Noter', image_url= 'http://www.traillink.com/images/mapIcons/national/stateMarker50.png') myrobot.set_verification_token_info(credentials.VERIFICATION_TOKEN, credentials.ST) myrobot.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, credentials.RPC_BASE[domain]) appengine_robot_runner.run(myrobot, debug=True, extra_handlers=[('/web/create', lambda: CreateHandler(myrobot)) ])
if field.get('extra'): first_line = '%s (%s)' % (first_line, field['extra']) first_line = '%s' % first_line self.blip.append(first_line) self.blip.append(element.Input(field['name'])) def get_input(self, name): for element_index, element in self.blip._elements.items(): if hasattr(element, 'name') and element.name == name: return element, element_index return None, None def get_input_value(self, name): input = self.blip.first(element.Input, name=name) return input.value().value if __name__ == '__main__': submitty = robot.Robot( 'Submitty', image_url='http://submitty-bot.appspot.com/img/submitty_avatar.png', profile_url='http://code.google.com/apis/wave/') submitty.register_handler(events.WaveletSelfAdded, OnSelfAdded) submitty.register_handler(events.DocumentChanged, OnBlipSubmitted, context=[events.Context.ALL]) submitty.register_handler(events.BlipSubmitted, OnBlipSubmitted) submitty.register_handler(events.GadgetStateChanged, OnGadgetStateChanged) submitty.register_handler(events.FormButtonClicked, OnButtonClicked) appengine_robot_runner.run(submitty, debug=True)
def get(self): domain = 'googlewave.com' addresses = self.request.get('addresses').split(',') wavelet = self._robot.new_wave(domain=domain, participants=addresses, submit=True) wavelet.title = ('I found you on the Google I/O Attendees map..') self._robot.submit(wavelet) url = 'https://wave.google.com/wave/#restored:wave:%s' % wavelet.wave_id self.redirect(url) if __name__ == '__main__': appid = os.environ['APPLICATION_ID'] r = robot.Robot( ROBOT_NAME.capitalize(), image_url='http://io2010-bot.appspot.com/img/thumbnail.png', profile_url='http://code.google.com/events/io') r.set_verification_token_info(credentials.VERIFICATION_TOKEN, credentials.ST) r.setup_oauth(credentials.CONSUMER_KEY, credentials.CONSUMER_SECRET, server_rpc_base='http://gmodules.com/api/rpc') appengine_robot_runner.run( r, debug=True, extra_handlers=[('/web/savelocation', lambda: SaveLocation(r)), ('/web/removelocation', lambda: RemoveLocation(r)), ('/web/getpersoninfo', lambda: GetPersonInfo()), ('/web/makewave', lambda: MakeWave(r))])
logging.info(url) js = urlfetch.fetch(url=url).content results = simplejson.loads(js)['responseData']['results'] randInt = random.randint(0, (len(results) - 1)) result = results[randInt] image = document.Image(result['tbUrl'], int(result['tbWidth']), int(result['tbHeight'])) childBlip = blip.CreateChild() childBlip.GetDocument().SetText(text + '\n' + 'Mmm... ' + thing + '\n') childBlip.GetDocument().AppendElement(image) def OnRobotAdded(properties, context): rootWavelet = context.GetRootWavelet() rootWavelet.SetTitle('Welcome to the Spooky House!') rootBlip = context.GetBlipById(rootWavelet.GetRootBlipId()) rootDoc = rootBlip.GetDocument() rootDoc.AppendElement( document.Gadget('http://tricky-bot.appspot.com/gadget.xml')) if __name__ == '__main__': myRobot = robot.Robot( 'Tricky', version='2', image_url='http://tricky-bot.appspot.com/images/avatar.png', profile_url='http://tricky-bot.appspot.com/') myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted) myRobot.Run()
import logging def OnRobotAdded(properties, context): """Invoked when the robot has been added.""" root_wavelet = context.GetRootWavelet() #def OnDocumentChanged(properties, context): def OnBlipSubmitted(properties, context): """Scan the wave to look for any special characters we should convert.""" blip = context.GetBlipById(properties['blipId']) blipDoc = blip.GetDocument() text = blipDoc.GetText() match = text.find('<3') if match > -1: blipDoc.DeleteRange(document.Range(match, match + 2)) blipDoc.InsertElement( match, document.Gadget('http://supasmiley-bot.appspot.com/gadget.xml')) if __name__ == '__main__': myRobot = robot.Robot('Supa Smiley', image_url='', version='1') myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) myRobot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted) myRobot.RegisterHandler(events.DOCUMENT_CHANGED, OnBlipSubmitted) myRobot.Run()
def Bannerize(phrase): url = 'http://www.google.com/chart?chst=d_bubble_texts_big&chld=bb|49D130|FFFFFF|%s' % phrase.replace( ' ', '+').replace('&', '%26') image = element.Image(url=url) return image def OnAnnotationChanged(event, wavelet): """Actual linking.""" blip = event.blip text = blip.text # construct the todo outside of the loop to avoid # influencing what we're observing: todo = [] for ann in blip.annotations: if ann.name == ROBOT_KEY: todo.append((ann.start, ann.end, ann.value)) for start, end, value in todo: payload = text[start:end] blip.range(start, end).clear_annotation(ROBOT_KEY) blip.at(end).insert(Bannerize(payload)) if __name__ == '__main__': robotty = robot.Robot('Bannerize', image_url='', profile_url='') robotty.register_handler(events.AnnotatedTextChanged, OnAnnotationChanged, filter=ROBOT_KEY) robotty.register_handler(events.WaveletSelfAdded, OnAnnotationChanged) appengine_robot_runner.run(robotty, debug=True)
# insert a reply, and add some text to the reply reply = org_wavelet.reply() reply.append('Replying from blind_wavelet works') # add a tag org_wavelet.tags.append('blindtag') # again we have to explicitly submit the operations to the other # wavelet org_wavelet.submit_with(wavelet) def ProfileHandler(name): if name == 'proxy': return { 'name': 'Douwe', 'imageUrl': 'http://www.igourmet.com/images/topics/douwe1.jpg', 'profileUrl': 'http://twitter.com/dosinga' } if __name__ == '__main__': sinky = robot.Robot( 'Kitchensinky', image_url='http://kitchensinky.appspot.com/public/avatar.png') sinky.register_handler(events.WaveletSelfAdded, OnSelfAdded) sinky.register_handler(events.WaveletCreated, OnWaveletCreated) sinky.register_handler(events.BlipSubmitted, OnBlipSubmitted) sinky.register_profile_handler(ProfileHandler) appengine_robot_runner.run(sinky, debug=True)
# You can read "state" data of gadget like this. # edited_gadget.count corresponds to value for key "count" # in gadget state. counts[edited_blip.GetId()] = int(edited_gadget.count) else: counts[edited_blip.GetId()] = 0 subjects[edited_blip.GetId()] = ( edited_blip.GetDocument().GetText().strip().split('\n')[0]) summary = '' for blip_id, count in sorted(counts.iteritems(), key=lambda (k, v): -v): summary += '%s (%s): %s\n' % (subjects[blip_id], blip_id, count) root_blip.GetDocument().SetText(summary) else: # Adds gadget to the blip. edited_gadget = document.Gadget(GADGET_URL) edited_blip.GetDocument().AppendElement(edited_gadget) if __name__ == '__main__': # Change this to your registered application name. app_name = 'your-app-name' my_robot = robot.Robot( app_name, image_url='http://%s.appspot.com/images/icon.png' % app_name, # Forces reloading every time, useful for debugging. version=str(int(time.time())), profile_url='http://%s.appspot.com/' % app_name) my_robot.RegisterHandler(events.BLIP_SUBMITTED, OnBlipSubmitted) my_robot.Run()