From 76a4785a0f93d5e7eb761f7b24f9b7816b811c57 Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Tue, 2 Aug 2022 23:40:40 -0400 Subject: [PATCH] Added Date to Config struct --- cmd/advanced.go | 3 ++- cmd/history.go | 15 +++++++-------- cmd/main.go | 7 +++++++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cmd/advanced.go b/cmd/advanced.go index 5840590..fb3602c 100644 --- a/cmd/advanced.go +++ b/cmd/advanced.go @@ -61,7 +61,8 @@ func advancedMenu(app *Application) { var validLoc bool for !validLoc { getPreciseLocation(app) - getHistorical(app.Client) + getDate(app) + getHistoricalData(app.Client, app) } if app.Forecast.Main.Temp != 0.00 { diff --git a/cmd/history.go b/cmd/history.go index 25e4cb0..ea94fef 100644 --- a/cmd/history.go +++ b/cmd/history.go @@ -8,31 +8,29 @@ import ( pb "codeberg.org/andcscott/weather-cli/proto" ) -func getDate(app *Application) (int32, int32, int32) { - - var year, month, day int32 +// Get a date from the user and save it to the config +func getDate(app *Application) { fmt.Print("Enter 4-digit year: ") - - _, err := fmt.Scanf("%d", &year) + _, err := fmt.Scanf("%d", &app.Config.Date.Year) if err != nil { fmt.Println("Invalid year") } fmt.Print("Enter month (1-12): ") - _, err = fmt.Scanf("%d", &month) + _, err = fmt.Scanf("%d", &app.Config.Date.Month) if err != nil { fmt.Println("Invalid year") } fmt.Print("Enter day (1-31): ") - _, err = fmt.Scanf("%d", &day) + _, err = fmt.Scanf("%d", &app.Config.Date.Day) if err != nil { fmt.Println("Invalid year") } - return year, month, day } +// Query SimplrWeather for date in Unix time func getUnixTime(c pb.RouteGuideClient) int32 { var year, month, day int32 @@ -48,6 +46,7 @@ func getUnixTime(c pb.RouteGuideClient) int32 { return res.Unixtime } +// Query SimplrWeather for historical data func getHistoricalData(c pb.RouteGuideClient, app *Application) { var lat, lon, year, month, day int32 diff --git a/cmd/main.go b/cmd/main.go index 35e5df3..e2cdd90 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -32,11 +32,18 @@ type Forecast struct { Wind Wind `json:"wind"` } +type Date struct { + Year int32 + Month int32 + Day int32 +} + type Config struct { Units string `json:"units"` Location string `json:"loc"` Longitude string `json:"lat"` Latitude string `json:"lon"` + Date Date ApiKey string `json:"appid"` }