comparison bots/bigastbot.py @ 1:2a288d2cb88c

add unread_to_mqtt bridge
author drewp@bigasterisk.com
date Tue, 11 Feb 2025 19:20:47 -0800
parents 96f842f12121
children
comparison
equal deleted inserted replaced
0:96f842f12121 1:2a288d2cb88c
1 import asyncio
2 from typing import AsyncGenerator, cast
3
1 import zulip 4 import zulip
2 from kubernetes import client, config 5 from kubernetes import client, config
3 6
4 config.load_kube_config() 7 config.load_kube_config()
5 8
33 msg = dict(type="stream", 36 msg = dict(type="stream",
34 to=[channelName], 37 to=[channelName],
35 topic=topic, 38 topic=topic,
36 content=content) 39 content=content)
37 return self.zulip_client.send_message(msg) 40 return self.zulip_client.send_message(msg)
41
42 async def get_registration_and_events(
43 self, **register_kw) -> AsyncGenerator[dict, None]:
44 """yields the registration response, then the events as they come"""
45 reg = self.zulip_client.register(**register_kw)
46 yield reg
47
48 last = reg['last_event_id']
49 while True:
50 update = self.zulip_client.get_events(queue_id=reg['queue_id'],
51 last_event_id=last)
52 for ev in cast(list[dict], update['events']):
53 yield ev
54 last = max(last, ev['id'])
55
56 await asyncio.sleep(1)