vega/weatherbot/main.go
2020-04-09 18:11:15 -04:00

31 lines
637 B
Go

package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
var apiKey = "7501365e9803ca244bf100fb41084538"
var lat = "39.004608"
var long = "-76.875671"
func main() {
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)
}
fmt.Println(TodayToReport(report.Daily[0]))
}