vega/weatherbot/bot.go

31 lines
654 B
Go
Raw Normal View History

2020-04-15 15:13:31 -04:00
package weatherbot
2020-04-09 18:11:15 -04:00
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
var apiKey = "7501365e9803ca244bf100fb41084538"
var lat = "39.004608"
var long = "-76.875671"
2020-04-15 15:13:31 -04:00
func GetDailyReport() 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])
}