lighthouse/collector.sh

23 lines
995 B
Bash
Executable file

# Collects and logs data from the OpenShipData API and the OSM API
#
source ./secrets
# get ship data
osd_response=$(curl -s -G -d "key=$KEY" -d "ship=$MMSI" https://ais.marineplan.com/location/2/ship.json)
# get relevant data
lat=$(echo "$osd_response" | jq --raw-output .point.latitude)
lon=$(echo "$osd_response" | jq --raw-output .point.longitude)
bearing=$(echo "$osd_response" | jq --raw-output .bearingDeg)
speed=$(echo "$osd_response" | jq --raw-output .speedKmh)
echo "Le bateau est a $lat,$lon orientation $bearing a une vitesse de $speed km/h"
# get osm data
osm_response=$(curl -s -G -d "format=json" -d "lat=$lat" -d "lon=$lon" -d "accept-language=fr" https://nominatim.openstreetmap.org/reverse?)
town=$(echo "$osm_response" | jq --raw-output .address.town)
province=$(echo "$osm_response" | jq --raw-output .address.province)
country=$(echo "$osm_response" | jq --raw-output .address.country)
echo "La ville la plus proche est $town dans la province de $province, $country"