2010-02-19 16 views
13

ho voluto aggiungere 3 funzioni per il robot dal tutorial qui: http://code.google.com/apis/wave/extensions/robots/python-tutorial.htmlfare le cose semplici con un robot Google Wave

Prima di aggiungere tutte queste caratteristiche, il mio robot funziona come previsto. Ora le caratteristiche dispari si mostrano ancora (con "v2" nel bck del contenuto di blip), ma nessuna delle nuove funzionalità compare! Ho provato diversi modi alr, ancora non funziona. Così frustrante ... Di seguito è riportato il codice che ritengo sia più logico. Qualcuno può dirmi perché nessuno sembra funzionare? Grazie ...

Caratteristica 1 - voluto provare AppendText
Caratteristica 2 - voleva che il robot per rilevare un blip è presentata
Caratteristica 3 - voleva il robot per aggiungere un blip con il contenuto della vecchio blip cancellato.

from waveapi import events 
from waveapi import model 
from waveapi import robot 

def OnParticipantsChanged(properties, context): 
    """Invoked when any participants have been added/removed.""" 
    added = properties['participantsAdded'] 
    for p in added: 
    Notify(context) 

def OnRobotAdded(properties, context): 
    """Invoked when the robot has been added.""" 
    root_wavelet = context.GetRootWavelet() 
    """feature 1""" 
    root_wavelet.CreateBlip().GetDocument().SetText("I'm alive! v2").GetDocument().AppendText("xxx") 

def Notify(context): 
    root_wavelet = context.GetRootWavelet() 
    root_wavelet.CreateBlip().GetDocument().SetText("Hi everybody! v2") 

    """feature 2""" 
def OnBlipSubmitted(properties, context): 
    blip = context.GetBlipById(properties['blipId']) 
    blip.GetDocument().AppendText("xxx") 

    """feature 3""" 
def OnBlipDeleted(properties, context): 
    blip = context.GetBlipById(properties['blipId']) 
    contents = blip.GetDocument().GetText() 
    root_wavelet = context.GetRootWavelet() 
    root_wavelet.CreateBlip().GetDocument().SetText(contents) 

if __name__ == '__main__': 
    myRobot = robot.Robot('appName', 
     image_url='http://appName.appspot.com/icon.png', 
     version='1', 
     profile_url='http://appName.appspot.com/') 
    myRobot.RegisterHandler(events.WAVELET_PARTICIPANTS_CHANGED, OnParticipantsChanged) 
    myRobot.RegisterHandler(events.WAVELET_SELF_ADDED, OnRobotAdded) 
    """myRobot.RegisterHandler(events.BLIP_SUMBITTED, OnBlipSubmitted) 
    myRobot.RegisterHandler(events.BLIP_DELETED, OnBlipDeleted)""" 
    myRobot.Run() 

Edit: (Importante) Ho appena notato che sembra hv comportamento diverso in modalità normale vs modalità sandbox. In modalità normale vedo entrambi i blip "I'm alive! V2" e "Hi everyone! V2", ma nella modalità sandbox posso vedere solo il primo. Werid ... In nessun caso vedo il testo aggiunto ...

Il motivo per cui ho commentato questa parte "" "myRobot.RegisterHandler (events.BLIP_SUMBITTED, OnBlipSubmitted) myRobot.RegisterHandler (events.BLIP_DELETED, OnBlipDeleted) "" " è cos senza commentarlo, il robot non fa nulla!

+2

'events.BLIP_SUMBITTED' sembra destinata errano per me. –

risposta

1

events.BLIP_SUMBITTED dovrebbe essere events.BLIP_SUBMITTED