modularize weatherbot

This commit is contained in:
stryan 2020-04-15 15:13:31 -04:00
parent f23162d49a
commit 28ee3a0f2e
4 changed files with 23 additions and 3 deletions

3
weatherbot/go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.saintnet.tech/stryan/vega/weatherbot
go 1.14

View File

@ -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])
}

View File

@ -1,4 +1,4 @@
package main
package weatherbot
import (
"fmt"

View File

@ -1,4 +1,4 @@
package main
package weatherbot
type OneCallReport struct {
Lat int `json:"lat"`