#!/usr/bin/bash # 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" #curl -s -d "Donnees collectes" $NTFY_ENDPOINT # store values in file if ! [ -e "$DATA_FILE" ] ; then touch $DATA_FILE echo "timestamp,latitude,longitude,bearing,speed,town,province,country" >> $DATA_FILE fi if ! [ -w "$DATA_FILE" ] ; then echo "$DATA_FILE is not writeable" exit 1 fi timestamp=$(date -u +"%Y-%m-%d %H:%M:%S UTC") echo "\"$timestamp\",$lat,$lon,$bearing,$speed,\"$town\",\"$province\",\"$country\"" >> $DATA_FILE exit 0