Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -e
- # while :; do ./get-location.sh 'https://www.google.com/maps/rpc/locationsharing/read?authuser=0&hl=en&gl=bg&pb=....' 'out.gpx' ; ./update-map.sh 'out.gpx' 'map.html'; echo "[[[--- $(echo "$(cat "out2.gpx" | wc -l) - 7" | bc) ---]]] on $(date)" ; sleep 60; done
- latLonTimestamp="$(curl "${1}" -s | tail +2 | jq '(.[0][0][1][1][1]),(.[0][0][1][1][2]),(.[0][0][1][2])' )"
- lon="$(head -n 1 <<< "${latLonTimestamp}" | tail -n 1)"
- lat="$(head -n 2 <<< "${latLonTimestamp}" | tail -n 1)"
- timestamp="$(head -n 3 <<< "${latLonTimestamp}" | tail -n 1)"
- unixTimestamp="$(( "${timestamp}" / 1000 ))"
- time="$(date --utc +%FT%T.%3NZ -d @${unixTimestamp})"
- gpxLine=" <trkpt lon=\"${lon}\" lat=\"${lat}\"><time>${time}</time></trkpt>"
- filename="${2:-out.gpx}"
- if ! [ -f "${filename}" ]; then
- echo '<?xml version="1.0" encoding="UTF-8"?>' > "${filename}"
- echo '<gpx xmlns="http://www.topografix.com/GPX/1/1">' >> "${filename}"
- echo ' <trk>' >> "${filename}"
- echo ' <trkseg>' >> "${filename}"
- echo ' </trkseg>' >> "${filename}"
- echo ' </trk>' >> "${filename}"
- echo '</gpx>' >> "${filename}"
- fi
- matches="$(grep "${gpxLine}" "${filename}" || [[ ${?} == 1 ]])"
- if [ -z "${matches}" ]; then
- # remove </trkseg></trk></gpx>:
- content="$(head -n -3 "${filename}")"
- echo "${content}" > "${filename}"
- echo "${gpxLine}" >> "${filename}"
- echo ' </trkseg>' >> "${filename}"
- echo ' </trk>' >> "${filename}"
- echo '</gpx>' >> "${filename}"
- fi
Advertisement
Add Comment
Please, Sign In to add comment