mirror of
https://codeberg.org/andyscott/weather-cli.git
synced 2024-12-21 12:43:09 -05:00
Added Date to Config struct
This commit is contained in:
parent
29414b28c9
commit
76a4785a0f
3 changed files with 16 additions and 9 deletions
|
@ -61,7 +61,8 @@ func advancedMenu(app *Application) {
|
||||||
var validLoc bool
|
var validLoc bool
|
||||||
for !validLoc {
|
for !validLoc {
|
||||||
getPreciseLocation(app)
|
getPreciseLocation(app)
|
||||||
getHistorical(app.Client)
|
getDate(app)
|
||||||
|
getHistoricalData(app.Client, app)
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.Forecast.Main.Temp != 0.00 {
|
if app.Forecast.Main.Temp != 0.00 {
|
||||||
|
|
|
@ -8,31 +8,29 @@ import (
|
||||||
pb "codeberg.org/andcscott/weather-cli/proto"
|
pb "codeberg.org/andcscott/weather-cli/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDate(app *Application) (int32, int32, int32) {
|
// Get a date from the user and save it to the config
|
||||||
|
func getDate(app *Application) {
|
||||||
var year, month, day int32
|
|
||||||
|
|
||||||
fmt.Print("Enter 4-digit year: ")
|
fmt.Print("Enter 4-digit year: ")
|
||||||
|
_, err := fmt.Scanf("%d", &app.Config.Date.Year)
|
||||||
_, err := fmt.Scanf("%d", &year)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Invalid year")
|
fmt.Println("Invalid year")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Enter month (1-12): ")
|
fmt.Print("Enter month (1-12): ")
|
||||||
_, err = fmt.Scanf("%d", &month)
|
_, err = fmt.Scanf("%d", &app.Config.Date.Month)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Invalid year")
|
fmt.Println("Invalid year")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("Enter day (1-31): ")
|
fmt.Print("Enter day (1-31): ")
|
||||||
_, err = fmt.Scanf("%d", &day)
|
_, err = fmt.Scanf("%d", &app.Config.Date.Day)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Invalid year")
|
fmt.Println("Invalid year")
|
||||||
}
|
}
|
||||||
return year, month, day
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query SimplrWeather for date in Unix time
|
||||||
func getUnixTime(c pb.RouteGuideClient) int32 {
|
func getUnixTime(c pb.RouteGuideClient) int32 {
|
||||||
|
|
||||||
var year, month, day int32
|
var year, month, day int32
|
||||||
|
@ -48,6 +46,7 @@ func getUnixTime(c pb.RouteGuideClient) int32 {
|
||||||
return res.Unixtime
|
return res.Unixtime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Query SimplrWeather for historical data
|
||||||
func getHistoricalData(c pb.RouteGuideClient, app *Application) {
|
func getHistoricalData(c pb.RouteGuideClient, app *Application) {
|
||||||
|
|
||||||
var lat, lon, year, month, day int32
|
var lat, lon, year, month, day int32
|
||||||
|
|
|
@ -32,11 +32,18 @@ type Forecast struct {
|
||||||
Wind Wind `json:"wind"`
|
Wind Wind `json:"wind"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Date struct {
|
||||||
|
Year int32
|
||||||
|
Month int32
|
||||||
|
Day int32
|
||||||
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Units string `json:"units"`
|
Units string `json:"units"`
|
||||||
Location string `json:"loc"`
|
Location string `json:"loc"`
|
||||||
Longitude string `json:"lat"`
|
Longitude string `json:"lat"`
|
||||||
Latitude string `json:"lon"`
|
Latitude string `json:"lon"`
|
||||||
|
Date Date
|
||||||
ApiKey string `json:"appid"`
|
ApiKey string `json:"appid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue