modularize weatherbot
This commit is contained in:
parent
f23162d49a
commit
28ee3a0f2e
3
weatherbot/go.mod
Normal file
3
weatherbot/go.mod
Normal file
@ -0,0 +1,3 @@
|
||||
module git.saintnet.tech/stryan/vega/weatherbot
|
||||
|
||||
go 1.14
|
@ -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])
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package weatherbot
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -1,4 +1,4 @@
|
||||
package main
|
||||
package weatherbot
|
||||
|
||||
type OneCallReport struct {
|
||||
Lat int `json:"lat"`
|
||||
|
Loading…
Reference in New Issue
Block a user