From c465374e68e1a78812a1054352caffcc4e746116 Mon Sep 17 00:00:00 2001 From: Danglewood <85772166+deeleeramone@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:04:03 -0800 Subject: [PATCH] linting --- .../extensions/websockets/openbb_websockets/helpers.py | 8 ++++++-- .../openbb_intrinio/models/websocket_connection.py | 4 +++- .../polygon/openbb_polygon/models/websocket_connection.py | 6 +++--- .../polygon/openbb_polygon/utils/websocket_client.py | 5 +++-- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/openbb_platform/extensions/websockets/openbb_websockets/helpers.py b/openbb_platform/extensions/websockets/openbb_websockets/helpers.py index 914e8b70cfe..9c19fb8ae33 100644 --- a/openbb_platform/extensions/websockets/openbb_websockets/helpers.py +++ b/openbb_platform/extensions/websockets/openbb_websockets/helpers.py @@ -179,7 +179,7 @@ async def setup_database(results_path, table_name): "Unexpected error caused by an invalid SQLite database file." "Please check the path, and inspect the file if it exists." + f" -> {e}" - ) + ) from e async with aiosqlite.connect(results_path) as conn: await conn.execute( f""" @@ -195,7 +195,6 @@ async def setup_database(results_path, table_name): async def write_to_db(message, results_path, table_name, limit): """Write the WebSocket message to the SQLite database.""" # pylint: disable=import-outside-toplevel - import json # noqa import aiosqlite conn = await aiosqlite.connect(results_path) @@ -238,6 +237,11 @@ async def write_to_db(message, results_path, table_name, limit): ) await conn.commit() + except Exception as e: # pylint: disable=broad-except + raise OpenBBError( + f"Unexpected error encountered while inserting message into the database. -> {e.__class__.__name__}: {e}" + ) from e + finally: await conn.close() diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/websocket_connection.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/websocket_connection.py index c970c264eb2..4f1d385fdf5 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/models/websocket_connection.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/websocket_connection.py @@ -129,7 +129,9 @@ class IntrinioWebSocketData(WebSocketData): new_conditions = [] conditions = conditions.replace(" ", "") - for char in range(len(conditions)): + for char in range( + len(conditions) + ): # pylint: disable=consider-using-enumerate if trade_type == "trade": new_conditions.append( TRADE_CONDITIONS.get(conditions[char], conditions[char]) diff --git a/openbb_platform/providers/polygon/openbb_polygon/models/websocket_connection.py b/openbb_platform/providers/polygon/openbb_polygon/models/websocket_connection.py index 59e726eb0a3..2594dd33c1f 100644 --- a/openbb_platform/providers/polygon/openbb_polygon/models/websocket_connection.py +++ b/openbb_platform/providers/polygon/openbb_polygon/models/websocket_connection.py @@ -353,9 +353,9 @@ class PolygonCryptoTradeWebSocketData(WebSocketData): """Validate the conditions.""" if v is None or isinstance(v, list) and v[0] == 0: return None - elif isinstance(v, list) and v[0] == 1: + if isinstance(v, list) and v[0] == 1: return "sellside" - elif isinstance(v, list) and v[0] == 2: + if isinstance(v, list) and v[0] == 2: return "buyside" return str(v) @@ -1200,7 +1200,7 @@ class PolygonWebSocketData(Data): or MODEL_MAP.get(data.get("type", "")) ) if not model: - return super().__new__(cls) + return super().__new__(cls) # pylint: disable=E1120 return model.model_validate(data) # type: ignore diff --git a/openbb_platform/providers/polygon/openbb_polygon/utils/websocket_client.py b/openbb_platform/providers/polygon/openbb_polygon/utils/websocket_client.py index ecb51e9265d..4daab5892a6 100644 --- a/openbb_platform/providers/polygon/openbb_polygon/utils/websocket_client.py +++ b/openbb_platform/providers/polygon/openbb_polygon/utils/websocket_client.py @@ -294,8 +294,9 @@ if __name__ == "__main__": logger.error("PROVIDER ERROR: WebSocket connection closed") except Exception as e: # pylint: disable=broad-except - msg = f"PROVIDER ERROR: {e.__class__.__name__} -> {e}" - logger.error(msg) + ERR = f"PROVIDER ERROR: {e.__class__.__name__} -> {e}" + logger.error(ERR) finally: + loop.stop() sys.exit(0)