-
Notifications
You must be signed in to change notification settings - Fork 8
/
extension_eim.py
49 lines (40 loc) · 1.24 KB
/
extension_eim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
'''
Usage
pip install codelab_adapter_client
'''
import time
import logging
from codelab_adapter_client import AdapterNode
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
class EIMNode(AdapterNode):
'''
Everything Is Message
'''
def __init__(self):
super().__init__()
self.logger = logger
# self.EXTENSION_ID = "eim" # default: eim
def extension_message_handle(self, topic, payload):
print(topic, payload, type(payload))
if type(payload) == str:
self.logger.info(f'scratch eim message:{payload}')
return
elif type(payload) == dict:
self.logger.info(f'eim message:{payload}')
self.publish({"payload": payload})
def run(self):
i = 0
while self._running:
message = self.message_template()
message["payload"]["content"] = str(i) # topic可选
self.publish(message)
time.sleep(1)
i += 1
if __name__ == "__main__":
try:
node = EIMNode()
node.receive_loop_as_thread() # run extension_message_handle, noblock(threaded)
node.run()
except KeyboardInterrupt:
node.terminate() # Clean up before exiting.