當前位置: 首頁>>代碼示例>>Python>>正文


Python YowNetworkLayer.EVENT_STATE_CONNECT屬性代碼示例

本文整理匯總了Python中yowsup.layers.network.YowNetworkLayer.EVENT_STATE_CONNECT屬性的典型用法代碼示例。如果您正苦於以下問題:Python YowNetworkLayer.EVENT_STATE_CONNECT屬性的具體用法?Python YowNetworkLayer.EVENT_STATE_CONNECT怎麽用?Python YowNetworkLayer.EVENT_STATE_CONNECT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在yowsup.layers.network.YowNetworkLayer的用法示例。


在下文中一共展示了YowNetworkLayer.EVENT_STATE_CONNECT屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def main():
    rospy.init_node("whatsapp_service")
    cred = credentials.WHATSAPP
    stackBuilder = YowStackBuilder()
    stack = (stackBuilder
             .pushDefaultLayers(True)
             .push(AideRosLayer)
             .build())
    loginfo("Stack built...")
    stack.setCredentials(cred)
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))  # sending the connect signal
    loginfo("Connected...")
    atexit.register(lambda: stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT)))

    th = threading.Thread(target=stack.loop)
    th.daemon = True
    th.start()
    loginfo("Running in background.")
    loginfo("All done. spinning.")
    while not rospy.is_shutdown():
        rospy.spin() 
開發者ID:Lambda-3,項目名稱:aide,代碼行數:23,代碼來源:whatsapp.py

示例2: onEvent

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def onEvent(self, layerEvent):
        credentials=self.getProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS)
        id=str(credentials[0])
        logger.info(id +': '+ layerEvent.getName())
        if layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
            logger.warning("Id: %s, Disconnected: %s" % (id,layerEvent.getArg("reason")))
            if layerEvent.getArg("reason") in ('Connection Closed','Ping Timeout'):
                time.sleep(20)
                logger.info("Id: %s, Issueing EVENT_STATE_CONNECT" % id)
                self.getStack().broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
            else:
                app=self.getProp('flaskApp')
                if hasattr(app,'layers') and 'credentials'  in app.layers:
                    del app.layers[credentials]
        elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_CONNECTED:
            logger.info("Id: %s Connected"% id) 
開發者ID:johntheknife,項目名稱:yowsuphttpinterface,代碼行數:18,代碼來源:layer.py

示例3: start

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def start(self):
        self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
        def startThread():
            try:
                self.stack.loop(timeout = 0.5, discrete = 0.5)
            except AuthError as e:
                print("Auth Error, reason %s" % e)
            except KeyboardInterrupt:
                print("\nYowsdown KeyboardInterrupt")
                sys.exit(0)
            except Exception as e:
                print("\nYowsdown General Exception")
                print e
        t1=threading.Thread(target=startThread)
        t1.daemon=True
        t1.start() 
開發者ID:johntheknife,項目名稱:yowsuphttpinterface,代碼行數:18,代碼來源:stack.py

示例4: listen

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def listen(self):
        """
        Starts the Yowsup listener

        :return: None
        """
        self.stack.broadcastEvent(
            YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)
        )
        self.stack.loop() 
開發者ID:namboy94,項目名稱:kudubot,代碼行數:12,代碼來源:WhatsappConnection.py

示例5: start

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def start(self):
        self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
        try:
            self.stack.loop()
        except AuthError as e:
            print("Authentication Error: %s" % e.message) 
開發者ID:svub,項目名稱:whatsapp-rest-webservice,代碼行數:8,代碼來源:stack.py

示例6: start

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def start(self):
        "Starts the connection with Whatsapp servers,"
        self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
        try:
            logging.info("#" * 50)
            logging.info("\tServer started. Phone number: %s" % self.credentials[0])
            logging.info("#" * 50)
            self.stack.loop(timeout=2.0, discrete=2.0)
        except AuthError as e:
            logging.exception("Authentication Error: %s" % e.message)
        except Exception as e:
            logging.exception("Unexpected Exception: %s" % e.message) 
開發者ID:FredLoh,項目名稱:Chat-Bot,代碼行數:14,代碼來源:server.py

示例7: run

# 需要導入模塊: from yowsup.layers.network import YowNetworkLayer [as 別名]
# 或者: from yowsup.layers.network.YowNetworkLayer import EVENT_STATE_CONNECT [as 別名]
def run(self):
        print("Start WhatsappBot with PID: " + str(getpid()))

        layers = (
            EchoLayer,
            YowParallelLayer([YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer]),YowAxolotlLayer
        ) + YOWSUP_CORE_LAYERS
        
        self.stack = YowStack(layers, self.connection)
        self.stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, WhatsappBot.CREDENTIALS)         #setting credentials
        self.stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])    #whatsapp server address
        self.stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)              
        #self.stack.setProp(YowCoderLayer.PROP_RESOURCE, YowsupEnv.getCurrent())          #info about us as WhatsApp client
       
        # initialize the EchoStack with our connection to Telegram
        echoLayer = self.stack.getLayer(-1)
        echoLayer.init(self.connection)

        self.stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))   #sending the connect signal
	
        # inject an event into yowsup to load our file
        self.stack.broadcastEvent(YowLayerEvent("daytime"))

        # create our dummy stream handler
        Communication(self.connection, self.stack)
	
	# save our hashmap when the TelegramBot is terminated
        signal.signal(signal.SIGINT, self.save_to_file)
        signal.signal(signal.SIGTERM, self.save_to_file)

        # this is the WhatsappBot main loop
	self.stack.loop() 
開發者ID:LeoGe,項目名稱:whattelcopybot,代碼行數:34,代碼來源:whatsapp_bot.py


注:本文中的yowsup.layers.network.YowNetworkLayer.EVENT_STATE_CONNECT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。