3030context .load_cert_chain (certfile = 'client_cert.pem' , keyfile = 'client_key.pem' )
3131
3232# Connect to server
33- hostname = 'x.x.x.x '
34- port = 8089
33+ hostname = '134.199.213.125 '
34+ port = 9009
3535
3636def get_sar (mmsi : str ) -> bool :
3737 """Get the AIS Search-And-Rescue (SAR) status of a given MMSI.
@@ -56,7 +56,7 @@ def get_sar(mmsi: str) -> bool:
5656
5757def create_cot_event (message : dict ):
5858 now = datetime .datetime .now (datetime .timezone .utc )
59- stale = now + datetime .timedelta (minutes = 2 )
59+ stale = now + datetime .timedelta (minutes = 10 )
6060
6161 print (message ['Message' ]['PositionReport' ])
6262 print (message )
@@ -78,7 +78,7 @@ def create_cot_event(message: dict):
7878async def connect_ais_stream ():
7979 async with websockets .connect ("wss://stream.aisstream.io/v0/stream" ) as websocket :
8080 subscribe_message = {
81- "APIKey" : "" ,
81+ "APIKey" : "4a98e66f38997bf8dc62226380434734886e4efb " ,
8282 "BoundingBoxes" : [[[- 90 , - 180 ], [90 , 180 ]]],
8383 "FilteringMMSI" : ["368207620" , "367719770" , "211476060" ],
8484 "FilderingMessageTypes" : ["PositionReport" ]
@@ -99,10 +99,12 @@ async def connect_ais_stream():
9999 with context .wrap_socket (sock , server_hostname = hostname ) as ssock :
100100 ssock .sendall (b )
101101 data = ssock .recv (1024 )
102+ await asyncio .sleep (1 )
102103
103104
104- def main ():
105- asyncio .run (asyncio .run (connect_ais_stream ()))
106-
107105if __name__ == "__main__" :
108- main ()
106+ while True :
107+ try :
108+ asyncio .run (asyncio .run (connect_ais_stream ()))
109+ except :
110+ continue
0 commit comments