diff --git a/weatherbot/go.mod b/weatherbot/go.mod new file mode 100644 index 0000000..03b2b05 --- /dev/null +++ b/weatherbot/go.mod @@ -0,0 +1,3 @@ +module git.saintnet.tech/stryan/vega/weatherbot + +go 1.14 diff --git a/weatherbot/main.go b/weatherbot/main.go index 23cafc7..b39b70a 100644 --- a/weatherbot/main.go +++ b/weatherbot/main.go @@ -1,4 +1,4 @@ -package main +package weatherbot import ( "encoding/json" @@ -28,3 +28,20 @@ func main() { } fmt.Println(TodayToReport(report.Daily[0])) } + +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]) +} diff --git a/weatherbot/today.go b/weatherbot/today.go index c8e9d76..7284a67 100644 --- a/weatherbot/today.go +++ b/weatherbot/today.go @@ -1,4 +1,4 @@ -package main +package weatherbot import ( "fmt" diff --git a/weatherbot/types.go b/weatherbot/types.go index b94aeec..cbcd7da 100644 --- a/weatherbot/types.go +++ b/weatherbot/types.go @@ -1,4 +1,4 @@ -package main +package weatherbot type OneCallReport struct { Lat int `json:"lat"`