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"
|
|
|
|
)
|
|
|
|
|
2020-04-15 16:11:58 -04:00
|
|
|
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)
|
2020-04-15 15:13:31 -04:00
|
|
|
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])
|
|
|
|
}
|