aisstream / issues

7 stars 3 forks source link

[User Issue] Help request for getting more data- seeking for Python code help #43

Open valfredini opened 10 months ago

valfredini commented 10 months ago

I am no t a programmer but using your python esample i was able to get most of the info i was looking for . I use "aisstream" occasionally but i would like to get some other info and i do not know how to modify the code to get those info.

Is there anyone tha modifing the python esample can add in the pritout the vassel NAME actual SPEED actual DIRECTION (0-359)

I am not able to do that

here below the code i am using now :import asyncio import websockets import json from datetime import datetime, timezone

async def connect_ais_stream():

async with websockets.connect("wss://stream.aisstream.io/v0/stream") as websocket:
    subscribe_message = {"APIKey": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                         "BoundingBoxes": [[[46.6018, -12.6777], [43.444,-1.9315]]],
                         "FiltersShipMMSI": ["247999000"],# Optional!
                         "FilterMessageTypes": ["PositionReport"]} # Optional!

    subscribe_message_json = json.dumps(subscribe_message)
    await websocket.send(subscribe_message_json)
    async for message_json in websocket:
        message = json.loads(message_json)
        message_type = message["MessageType"]

        if message_type == "PositionReport":
            # the message parameter contains a key of the message type which contains the message itself
            ais_message = message['Message']['PositionReport']
            print(f"[{datetime.now(timezone.utc)}] ShipId: {ais_message['UserID']} Latitude: {ais_message['Latitude']} Longitude: {ais_message['Longitude']}")

if name == "main": asyncio.run(asyncio.run(connect_ais_stream()))

obergman commented 9 months ago

print(ais_message['Cog']) print(ais_message['Sog']) print(message['MetaData']['ShipName'])