~ecs/quaternia

99803c3a2ef768243cfb21a4ec7ecfd9c9c886c7 — Eyal Sawady 13 days ago f4baf5e
.w: do reverse geocoding
1 files changed, 15 insertions(+), 4 deletions(-)

M wttr.go
M wttr.go => wttr.go +15 -4
@@ 29,6 29,8 @@ func (wttr) Output(args []string, f Flags, c *girc.Client, e girc.Event, ch chan
	}
	when := time.Now()

	geocoder := openstreetmap.Geocoder()

	if len(args) > 0 {
		location, err :=
			openstreetmap.Geocoder().Geocode(args[0])


@@ 46,6 48,15 @@ func (wttr) Output(args []string, f Flags, c *girc.Client, e girc.Event, ch chan
		}
	}

	addr, err := geocoder.ReverseGeocode(loc.Lat, loc.Long)
	name := ""
	if err != nil || addr == nil {
		name = fmt.Sprintf("%f,%f", loc.Lat, loc.Long)
	} else {
		name = fmt.Sprintf("%s, %s, %s", addr.Suburb, addr.State,
			addr.CountryCode)
	}

	coords := &owm.Coordinates{
		Latitude:  loc.Lat,
		Longitude: loc.Long,


@@ 82,8 93,8 @@ func (wttr) Output(args []string, f Flags, c *girc.Client, e girc.Event, ch chan
		for _, weather := range w.Weather {
			desc = desc + weather.Description
		}
		ch <- fmt.Sprintf("weather in %f,%f: %s, %.2f°F", loc.Lat,
			loc.Long, desc, w.Main.Temp)
		ch <- fmt.Sprintf("weather in %s: %s, %.2f°F", name, desc,
			w.Main.Temp)
		return
	}
	fc, err := owm.NewForecast("5", "f", "en", GetConfig(c).OWMKey)


@@ 107,8 118,8 @@ func (wttr) Output(args []string, f Flags, c *girc.Client, e girc.Event, ch chan
	for _, weather := range w.Weather {
		desc = desc + weather.Description
	}
	ch <- fmt.Sprintf("weather in %f,%f at %s: %s, %.2f°F", loc.Lat,
		loc.Long, when.Format(time.RFC1123Z), desc, w.Main.Temp)
	ch <- fmt.Sprintf("weather in %s at %s: %s, %.2f°F", name,
		when.Format(time.RFC1123Z), desc, w.Main.Temp)
}

func init() {