vega/weatherbot/bot.go

27 lines
583 B
Go

package weatherbot
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func GetDailyReport(apikey, lat, long string) string {
oneCallUrl := fmt.Sprintf("https://api.openweathermap.org/data/2.5/onecall?lat=%v&lon=%v&units=imperial&appid=%v", lat, long, apikey)
response, err := http.Get(oneCallUrl)
if err != nil {
log.Fatalf("The HTTP request failed with error %s\n", err)
}
data, _ := ioutil.ReadAll(response.Body)
var report OneCallReport
err = json.Unmarshal(data, &report)
if err != nil {
log.Fatal(err)
}
return TodayToReport(report.Daily[0])
}