Added Date to Config struct

This commit is contained in:
Andrew Scott 2022-08-02 23:40:40 -04:00
parent 29414b28c9
commit 76a4785a0f
Signed by: a
GPG key ID: 3EB62D0BBB8DB381
3 changed files with 16 additions and 9 deletions

View file

@ -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 {

View file

@ -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

View file

@ -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"`
}