social media crossposting tool. 3rd time's the charm
mastodon misskey crossposting bluesky

i have no idea what i'm doing

zenfyr.dev de19853a 4c457fee

verified
+44 -53
+14 -17
bluesky/input.py
··· 303 303 url += "&wantedCollections=app.bsky.feed.repost" 304 304 url += f"&wantedDids={self.did}" 305 305 306 - async for ws in websockets.connect( 307 - url, 308 - ping_interval=20, 309 - ping_timeout=10, 310 - close_timeout=5, 311 - ): 306 + while True: 312 307 try: 313 - self.log.info("Listening to '%s'...", env.JETSTREAM_URL) 308 + async with websockets.connect( 309 + url, 310 + ping_interval=20, 311 + ping_timeout=10, 312 + close_timeout=5, 313 + ) as ws: 314 + self.log.info("Listening to '%s'...", env.JETSTREAM_URL) 314 315 315 - async def listen_for_messages(): 316 316 async for msg in ws: 317 317 self.submitter(lambda: self._accept_msg(msg)) 318 318 319 - listen = asyncio.create_task(listen_for_messages()) 320 - 321 - _ = await asyncio.gather(listen) 322 319 except websockets.ConnectionClosedError as e: 323 - self.log.error(e, stack_info=True, exc_info=True) 324 - self.log.info("Reconnecting to '%s'...", env.JETSTREAM_URL) 325 - continue 320 + self.log.warning("Connection closed: %s", e) 326 321 except TimeoutError as e: 327 - self.log.error("Connection timeout: '%s'", e) 328 - self.log.info("Reconnecting to '%s'...", env.JETSTREAM_URL) 329 - continue 322 + self.log.warning("Connection timeout: '%s'", e) 323 + except Exception as e: 324 + self.log.error("Unexpected error: '%s'", e, exc_info=True) 325 + 326 + self.log.info("Reconnecting to '%s'...", env.JETSTREAM_URL)
+15 -18
mastodon/input.py
··· 248 248 async def listen(self): 249 249 url = f"{self.streaming_url}/api/v1/streaming?stream=user" 250 250 251 - async for ws in websockets.connect( 252 - url, 253 - additional_headers={"Authorization": f"Bearer {self.options.token}"}, 254 - ping_interval=20, 255 - ping_timeout=10, 256 - close_timeout=5, 257 - ): 251 + while True: 258 252 try: 259 - self.log.info("Listening to '%s'...", self.streaming_url) 253 + async with websockets.connect( 254 + url, 255 + additional_headers={"Authorization": f"Bearer {self.options.token}"}, 256 + ping_interval=20, 257 + ping_timeout=10, 258 + close_timeout=5, 259 + ) as ws: 260 + self.log.info("Listening to '%s'...", self.streaming_url) 260 261 261 - async def listen_for_messages(): 262 262 async for msg in ws: 263 263 self.submitter(lambda: self._accept_msg(msg)) 264 264 265 - listen = asyncio.create_task(listen_for_messages()) 266 - 267 - _ = await asyncio.gather(listen) 268 265 except websockets.ConnectionClosedError as e: 269 - self.log.error(e, stack_info=True, exc_info=True) 270 - self.log.info("Reconnecting to '%s'...", self.streaming_url) 271 - continue 266 + self.log.warning("Connection closed: %s", e) 272 267 except TimeoutError as e: 273 - self.log.error("Connection timeout: '%s'", e) 274 - self.log.info("Reconnecting to '%s'...", self.streaming_url) 275 - continue 268 + self.log.warning("Connection timeout: '%s'", e) 269 + except Exception as e: 270 + self.log.error("Unexpected error: '%s'", e, exc_info=True) 271 + 272 + self.log.info("Reconnecting to '%s'...", self.streaming_url)
+15 -18
misskey/input.py
··· 243 243 streaming: str = f"{'wss' if self.url.startswith('https') else 'ws'}://{self.url.split('://', 1)[1]}" 244 244 url: str = f"{streaming}/streaming?i={self.options.token}" 245 245 246 - async for ws in websockets.connect( 247 - url, 248 - ping_interval=20, 249 - ping_timeout=10, 250 - close_timeout=5, 251 - ): 246 + while True: 252 247 try: 253 - self.log.info("Listening to '%s'...", streaming) 254 - await self._subscribe_to_home(ws) 248 + async with websockets.connect( 249 + url, 250 + ping_interval=20, 251 + ping_timeout=10, 252 + close_timeout=5, 253 + ) as ws: 254 + self.log.info("Listening to '%s'...", streaming) 255 + await self._subscribe_to_home(ws) 255 256 256 - async def listen_for_messages(): 257 257 async for msg in ws: 258 258 self.submitter(lambda: self._accept_msg(msg)) 259 259 260 - listen = asyncio.create_task(listen_for_messages()) 261 - 262 - _ = await asyncio.gather(listen) 263 260 except websockets.ConnectionClosedError as e: 264 - self.log.error(e, stack_info=True, exc_info=True) 265 - self.log.info("Reconnecting to '%s'...", streaming) 266 - continue 261 + self.log.warning("Connection closed: %s", e) 267 262 except TimeoutError as e: 268 - self.log.error("Connection timeout: '%s'", e) 269 - self.log.info("Reconnecting to '%s'...", streaming) 270 - continue 263 + self.log.warning("Connection timeout: '%s'", e) 264 + except Exception as e: 265 + self.log.error("Unexpected error: '%s'", e, exc_info=True) 266 + 267 + self.log.info("Reconnecting to '%s'...", streaming)