#!/bin/sh -e

cd /home/phoebos/go/src/github.com/aabacchus/where

# make map
./where -c creds.json >/dev/null

# count number of markers
num=$(jq '[.[] | select(.Lat != 0) | select(.Lng != 0)] | length' ips.json)
#now=$(date -u --rfc-3339=seconds)
now=$(stat -c '%y' map.png)

# update webpage
echo "<!DOCTYPE html>
<html>
<!-- generated by /home/phoebos/go/src/github.com/aabacchus/where/run-update-script.sh -->
<!-- copyright 2021 ~phoebos <phoebos@ctrl-c.club> -->
<!-- map images are copyright MapBox -->
<head>
<meta charset=\"utf-8\" />
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>map</title>
<link rel=\"stylesheet\" href=\"style.css\">
</head>
<body>
<h1>Map of Ctrl-C.Club users</h1>
<p>To opt-in, add a file named <code style=\"font-family: monospace\">.here</code> to your home directory.
The map is updated every 30 minutes.</p>
<p>If you'd like to see a dynamic map you can zoom, and don't mind JavaScript, see <a href=\"dynamic.html\">here</a>.</p>
<img src=\"map.png\" style=\"max-width: 100%\">
<p><a href=\"https://github.com/aabacchus/where\">Repo</a></p>
<p><a href=\"/~bear/where.html\">Inspiration</a></p>
<footer style='font-size: small'>$num users plotted, last updated $now</footer>
</body>
</html>" > /home/phoebos/public_html/old/map.html

# make gemini page
echo "# Map of Ctrl-C.Club users
To opt-in, add a file named .here to your home directory.
The map is updated every 30 minutes.
=> map.png map.png
$num users plotted, last updated $now" > /home/phoebos/public_gemini/old/map.gmi
