Compare commits

..

5 Commits

Author SHA1 Message Date
f5fe993105 Merge branch 'next' of sneak/sco into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-09-13 07:54:22 +00:00
6930389a39 Merge branch 'next' of sneak/sco into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-09-09 05:13:44 +00:00
ba484557b8 Merge branch 'next' of sneak/sco into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-09-09 04:34:11 +00:00
2ee81c19c8 Merge branch 'next' of sneak/sco into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-09-09 04:02:59 +00:00
b3c9157b3c Merge branch 'next' of sneak/sco into master
All checks were successful
continuous-integration/drone/push Build is passing
2020-09-09 03:36:31 +00:00

View File

@@ -13,7 +13,7 @@ import (
"github.com/rs/zerolog/log"
)
type AQIResponse struct {
type AQIResponse []struct {
DateObserved string `json:"DateObserved"`
HourObserved int `json:"HourObserved"`
LocalTimeZone string `json:"LocalTimeZone"`
@@ -29,19 +29,6 @@ type AQIResponse struct {
} `json:"Category"`
}
func formatAQIResponse(input *[]AQIResponse, zip string) string {
dinput := *input
in := dinput[0]
when := fmt.Sprintf("%s at %d:00 %s", in.DateObserved, in.HourObserved, in.LocalTimeZone)
bytes, err := json.Marshal(input)
if err != nil {
panic(err)
}
formatted := string(bytes)
out := fmt.Sprintf("# AQI for %s as of %s:\n %s", zip, when, formatted)
return out
}
func (b *Bot) HandleAirQualityRequest(channelid string, postid string, message string) {
// we are using a very bare image with no CA cert bundle
@@ -57,10 +44,10 @@ func (b *Bot) HandleAirQualityRequest(channelid string, postid string, message s
b.SendMsgToChannel("error, sorry", postid, channelid)
}
zip := matches[1]
zip4 := matches[1]
apikey := os.Getenv("AIRNOW_API_KEY")
url := fmt.Sprintf("http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=%s&distance=25&API_KEY=%s", zip, apikey)
url := fmt.Sprintf("http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=%s&distance=25&API_KEY=%s", zip4, apikey)
log.Info().Msgf("calculated url: `%s`", url)
@@ -82,9 +69,9 @@ func (b *Bot) HandleAirQualityRequest(channelid string, postid string, message s
data, _ := ioutil.ReadAll(resp.Body)
var parsedAQIResponse []AQIResponse
var parsedAQIResponse AQIResponse
log.Info().Msgf("aqi %s: %s", zip, data)
log.Info().Msgf("aqi %s: %s", zip4, data)
err = nil
err = json.Unmarshal([]byte(data), &parsedAQIResponse)
@@ -93,7 +80,5 @@ func (b *Bot) HandleAirQualityRequest(channelid string, postid string, message s
b.SendMsgToChannel("error deserializing AQI data", postid, channelid)
return
}
msg := formatAQIResponse(&parsedAQIResponse, zip)
b.SendMsgToChannel(msg, postid, channelid)
b.SendMsgToChannel(fmt.Sprintf("AQI for `%s`: \n```\n%+v\n```\n", zip4, parsedAQIResponse), postid, channelid)
}