where

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit a3c80e4d1acb73299315f5657c15c769dac079d0
parent 50293b2532891f939e027c83d9c893e8f69b0f72
Author: aabacchus <bvnfuller@gmail.com>
Date:   Fri, 26 Mar 2021 21:49:03 +0000

parse less clean ips

Diffstat:
MTODO | 1+
Mmapbox.go | 12++++++++++--
Mwhere.go | 31++++++++++++++++++++++++++-----
3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/TODO b/TODO @@ -1,3 +1,4 @@ +* Don't replace cache with 0,0 coords * Only get locations of opted-in users * Anonymize users who wish * Create webpage (interactive map?) diff --git a/mapbox.go b/mapbox.go @@ -17,7 +17,7 @@ type MapboxDetails struct { Uname string Style string Apikey string - Padding string + Padding int } // MapboxStatic creates a static image of a map @@ -31,12 +31,20 @@ func MapboxStatic(m []Marker, fname string, mbox MapboxDetails) error { // the field after auto is the dimensions of the png image // the parameters at the end (after the ?) are the access_token (required) // and padding (optional) - suffix := fmt.Sprintf("/auto/800x720?padding=%s&access_token=%s", mbox.Padding, mbox.Apikey) + suffix := fmt.Sprintf("/auto/800x720?padding=%d&access_token=%s", mbox.Padding, mbox.Apikey) var markersMapbox string for _, mark := range m { + // don't plot places with no data + if mark.Lat == 0 && mark.Lng == 0 { + continue + } markersMapbox += MarkerToMapbox(mark, "", "aa0500") + "," } + // if there were none left after removing those at (0,0), return + if len(markersMapbox) == 0 { + return fmt.Errorf("no markers with non-zero location") + } // remove the final comma markersMapbox = markersMapbox[:len(markersMapbox)-1] diff --git a/where.go b/where.go @@ -23,6 +23,7 @@ import ( "io/ioutil" "net/http" "os" + "strings" ) func usage() { @@ -37,10 +38,19 @@ func main() { flag.StringVar(&mboxDetails.Uname, "mboxu", "", "mapbox.com username") flag.StringVar(&mboxDetails.Apikey, "mboxa", "", "mapbox.com API key") flag.StringVar(&mboxDetails.Style, "mboxs", "", "mapbox map style") - flag.StringVar(&mboxDetails.Padding, "mboxp", "5", "mapbox map padding (a percentage without the %)") + flag.IntVar(&mboxDetails.Padding, "mboxp", 5, "mapbox map padding (a percentage without the %)") flag.Usage = usage flag.Parse() + /* + ips, err := exec.Command("who", "--ips").Output() + if err != nil { + log.Println(err) + } + fmt.Println(ips) + os.Exit(0) + */ + ips, err := getTestIps("whoips") if err != nil { fmt.Printf("error reading sample who --ips file: %s\n", err.Error()) @@ -50,11 +60,22 @@ func main() { responseChan := make(chan MarkResponse) var results = make([]Marker, len(lines)) for _, line := range lines { - if len(line) > 5 { - // if there's something messy eg. with mosh, ignore it (for now) - //line[4] = "" + ip := line[4] + if ip[0] == '(' { + if strings.Contains(ip, "mosh") { + ip = "0" + } else { + endidx := strings.Index(ip, ":") + if endidx == -1 { + endidx = strings.Index(ip, ")") + if endidx == -1 { + endidx = len(ip) + } + } + ip = ip[1:endidx] + } } - go ipLatLng(*apiKey, line[0], line[4], responseChan) + go ipLatLng(*apiKey, line[0], ip, responseChan) } var resp MarkResponse for i := range lines {